
Now that you’re logged into your Raspberry Pi via SSH, it’s time to prepare the system for a reliable and secure Nextcloud installation. We’ll start by updating the operating system, installing Snap, and then deploying Nextcloud using the official Snap package one of the simplest and most maintenance-friendly methods available.
The Snap version of Nextcloud bundles everything (web server, database, PHP, etc.) into a self-contained package. It handles automatic updates gracefully and is well-suited for Raspberry Pi hardware.
Run the following commands one by one:
sudo apt update
Before installing any new software, always bring your Raspberry Pi OS up to date. This ensures you have the latest security patches and package versions.
Raspberry Pi OS (Debian Bookworm-based) does not include Snap support by default. Install it with these commands:
sudo apt install snapd -y
To ensure you’re running the latest version of snapd itself, install the snapd snap:
sudo snap install snapd
Important: Reboot the Pi again after installing snapd:
sudo reboot
Log back in via SSH.
Now install the official Nextcloud Snap. This process may take several minutes as it downloads and sets up all components.
sudo snap install nextcloud
Once the installation finishes, Nextcloud will start automatically. You can check its status with:
sudo snap services nextcloud
Nextcloud runs on port 80 by default. Open a web browser on any device connected to the same network and navigate to your Raspberry Pi’s IP address:
(Replace IP-ADDRESS with the actual IP you found in your router.)
You will see the Nextcloud setup wizard. Create your admin account by entering:
Click Install to complete the initial setup. The process usually takes 1–2 minutes.
Here are some useful commands you may need later:
sudo snap restart nextcloud
sudo snap logs nextcloud
sudo snap refresh nextcloud
For optimal data protection and reliability, we recommend using an external HDD as the primary storage for your Nextcloud files, combined with a separate drive dedicated exclusively to backups.
Imagine losing your primary HDD or even the entire Raspberry Pi along with years of irreplaceable family photos, documents, and memories. With this setup, you’ll still have a complete, up-to-date copy of everything on your backup drive, ensuring your precious data remains safe even in the event of hardware failure.
This dual-drive strategy significantly reduces the risk of data loss and provides peace of mind, which is especially important when self-hosting personal and family data.
So now, we will configure two external hard drives on a Raspberry Pi: one for primary Nextcloud storage and a second for automated daily backups. This setup protects your data against drive failure or hardware issues while keeping everything accessible and easy to manage.
This guide provides the exact commands used to configure a Raspberry Pi running Raspberry Pi OS with Nextcloud (Snap installation).
lsblk
sudo mkdir -p /mnt/drive1 sudo mkdir -p /mnt/backup
sudo fdisk /dev/sdb
sudo mkfs.ntfs -f /dev/sdb1
sudo mount /dev/sdb1 /mnt/backup df -h
Edit the fstab file:
sudo nano /etc/fstab
Add the following entries (replace UUIDs with your actual values from blkid):
UUID=XXXXXXXXXXXXXX /mnt/drive1 ntfs-3g defaults,uid=root,gid=root,umask=007,noatime 0 0
UUID=YYYYYYYYYYYYYY /mnt/backup ntfs-3g defaults,uid=root,gid=root,umask=007,noatime 0 0
Test the configuration:
sudo mount -a
sudo ntfsfix /dev/sda1
The config file is located at:
sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php
Change the datadirectory line to:
'datadirectory' => '/mnt/drive1/nextcloud_data',
For Snap installations, also run
sudo snap connect nextcloud:removable-media
sudo mkdir -p /mnt/drive1/nextcloud_data
echo "# Nextcloud data directory" | sudo tee /mnt/drive1/nextcloud_data/.ncdata
sudo mkdir -p /mnt/backup/nextcloud_backup
sudo rsync -avh --delete /mnt/drive1/nextcloud_data/ /mnt/backup/nextcloud_backup/
crontab -e
Add the following line:
0 3 * * * rsync -a --delete /mnt/drive1/nextcloud_data/ /mnt/backup/nextcloud_backup/
df -h /mnt/drive1 /mnt/backup
The next guide explains the commands used to recover a Raspberry Pi from
emergency mode and manually mount external USB drives used for Nextcloud.