Feb 24, 2024 · Self-Hosting / Intermediate · ~4 MIN READ
Setup Nextcloud on Raspberry Pi
Build your own private cloud storage with Nextcloud on Ubuntu Server — step-by-step from imaging to securing access.
Introduction
Nextcloud is an open-source, self-hosted file sync/share platform. This guide shows how to install it on a Raspberry Pi running Ubuntu Server, then secure it with HTTPS and (optionally) place data on an external drive. Versions change, but the flow remains the same, adjust as needed.
Think of it like building your own post office instead of renting a mailbox at someone else’s. You control who has keys, where the mail actually goes, and nobody else gets to read your letters along the way.
Prerequisites
- Raspberry Pi (Pi 4 or newer recommended)
- microSD card (≥16 GB) + reader
- Reliable power + network with Internet access
- Basic terminal familiarity
1) Image Ubuntu Server
- Install Raspberry Pi Imager: Download here ↗
- In Imager, select your Pi model → Other general-purpose OS → Ubuntu → pick a current Ubuntu Server 64-bit LTS build.
- Open advanced settings (gear icon): set hostname, username/password, locale, and enable SSH.
- Write the image to your microSD, insert into the Pi, connect Ethernet (recommended), and power on.
2) Connect via SSH
On your computer’s terminal, SSH into the Pi (replace placeholders):
$ ssh <username>@<hostname-or-ip>
If the hostname doesn't resolve, use the Pi's IP address. Example:
ssh FL1GHT5@10.1.1.5
3) Update the system
Use apt (no need to mix apt and apt-get):
$ sudo apt update
$ sudo apt full-upgrade -y
4) Install Nextcloud (snap)
- Ensure snapd is present (Ubuntu Server usually includes it):
$ sudo apt install -y snapd
Install Nextcloud via snap:
$ sudo snap install nextcloud
Verify:
$ snap list
5) Open firewall (UFW)
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
$ sudo ufw allow OpenSSH
$ sudo ufw enable
6) First login (HTTP)
Visit http:// in your browser (e.g., http://10.1.1.5). Create the first admin account. We’ll switch to HTTPS shortly.
7) Set trusted domains
Edit the Nextcloud config. With the snap, it’s here: /var/snap/nextcloud/current/nextcloud/config/config.php
$ sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php
Only add hostnames/IPs (no http:// or https://):
Example snippet:
‘trusted_domains’ => array ( 0 => ‘localhost’, 1 => ‘nextcloud.example.com’, 2 => ‘10.1.1.5’, 3 => ‘203.0.113.10’, // optional: public IP ),
8) Enable HTTPS (Let’s Encrypt)
Make sure your DNS points nextcloud.example.com at your public IP and your router forwards ports 80/443 to the Pi.
$ sudo nextcloud.enable-https lets-encrypt
Follow prompts: agree to the terms, provide an email, and enter your domain name(s).
9) Restart services (if needed)
$ sudo snap disable nextcloud
$ sudo snap enable nextcloud
10) (Optional) Use an external drive for data
With the snap, Nextcloud expects data in /var/snap/nextcloud/common/nextcloud/data. The clean way to use an external disk is to mount the drive at that path (via a bind mount or direct mount), rather than pointing Nextcloud to a new arbitrary directory.
10.1 Identify the disk
$ lsblk -a
10.2 Partition & Format (Warning: Data Loss)
⚠️ This will erase the disk. Replace sda with your device.
$ sudo gdisk /dev/sda
Create a single Linux filesystem partition (type 8300), then:
$ sudo mkfs.ext4 -L nextclouddata /dev/sda1
10.3 Create a persistent mount
- Get the UUID:
$ sudo blkid /dev/sda1
Stop Nextcloud briefly and prepare mount point:
$ sudo snap stop nextcloud
$ sudo mkdir -p /var/snap/nextcloud/common/nextcloud
Move existing data (if any) out of the way first (backup!):
$ sudo mv /var/snap/nextcloud/common/nextcloud/data /var/snap/nextcloud/common/nextcloud/data.bak
Open /etc/fstab and add a mount line that targets the expected snap data path:
$ sudo nano /etc/fstab
Add a line like:
UUID=
Using uid=www-data, gid=www-data helps ensure the web server can read/write. Alternatively, mount normally and adjust ownership: sudo chown -R root:root or www-data:www-data depending on your model. For strict setups, consider a bind mount from /mnt/cloud into the snap path.
Mount and verify:
$ sudo mount -a
$ df -h
Finally, restart Nextcloud:
$ sudo snap start nextcloud
Resources
- Nextcloud admin manual, installation on Linux
- Guides from VULTR, DigitalOcean, and YouTube for alternate installs & disk management
Wrap-up
You now have Nextcloud running on your Pi, secured with HTTPS and optionally backed by an external drive. Keep your system updated, monitor disk health, and consider automatic backups of your data directory.