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):
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 full-upgrade -y
4) Install Nextcloud (snap)
- Ensure snapd is present (Ubuntu Server usually includes it):
- Install Nextcloud via snap:
Verify:
5) Open firewall (UFW)
$sudo ufw allow 443/tcp
$sudo ufw allow OpenSSH
$sudo ufw enable
6) First login (HTTP)
Visit http://<pi-ip> 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
Only add hostnames/IPs (no http:// or https://):
'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.
Follow prompts: agree to the terms, provide an email, and enter your domain name(s).
9) Restart services (if needed)
$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
10.2 Partition & Format (Warning: Data Loss)
⚠️ This will erase the disk. Replace sda with your device.
Create a single Linux filesystem partition (type 8300), then:
10.3 Create a persistent mount
- Get the UUID:
- Stop Nextcloud briefly and prepare mount point:
$sudo mkdir -p /var/snap/nextcloud/common/nextcloud
Move existing data (if any) out of the way first (backup!):
Open /etc/fstab and add a mount line that targets the expected snap data path:
UUID=<your-UUID> /var/snap/nextcloud/common/nextcloud/data ext4 defaults, uid=www-data, gid=www-data 0 2
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:
$df -h
Finally, restart 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.