If you are self-hosting your Ghost CMS website then you will need to make sure that everything is up to date. There is no one-click update for your Ghost CMS so you will need to do everything yourself to make sure you get the latest updates and stay up to do for security and performance.
If you don't want to do this yourself manually you can use get your website hosted directly by the team behind Ghost or find a 3rd party to handle the server maintenance.
But if you're anything like me, and want to try your hand with self-hosting on your own server like Digital Ocean (you can use my referral code to get $200 in credit over 60 days if you haven't set up your website there yet).
But if you've already got everything set up and just need to update everything here are the steps I take to maintain the server, the ghost-CLI & then update the ghost installation itself.
At the end, I’ve included a way to automate this entire sequence. However, I haven't fully tested this automation, so make sure to back up your data before attempting it or any of the following steps as a best practice.
Here are the steps I follow, that you can do as well.
1. Update the Server (Packages and Security)
Start by updating the server’s software, which includes installing security patches and any package updates.
# Update package lists
sudo apt-get update
# Upgrade installed packages
sudo apt-get upgrade -y
# Upgrade distribution packages (optional but recommended for major updates)
sudo apt-get dist-upgrade -y
# Remove unnecessary packages
sudo apt-get autoremove -y
# Clean up the package cache
sudo apt-get autoclean
2. Update Ghost-CLI
Ensure that the Ghost-CLI tool is up to date before updating Ghost itself.
# Update Ghost-CLI to the latest version
sudo npm install -g ghost-cli@latest
3. Update All Ghost Instances
Now, update each Ghost instance. If you have multiple instances, repeat these commands for each instance. You can automate this part if all your instances are located in predictable directories.
# Navigate to each Ghost instance directory and update
cd /var/www/your-ghost-instance
ghost update
For automation, if your Ghost instances are located under /var/www/ghost/, you can run the following:
# Loop through all Ghost instance directories and update each
for dir in /var/www/ghost/*/; do
cd "$dir"
ghost update
done
4. Post-Update Verification
After updating, check that all Ghost instances are running properly and that your websites are accessible.
# Check the status of all Ghost instances
ghost ls
# Optionally, visit your websites in a browser to verify they are functioning correctly.
5. Reboot (Optional)
If you performed a kernel update or if the server prompts you to reboot after updates:
sudo reboot
Optional: Automation Script (untested)
You can put all these commands into a single script to run everything with one command. Here’s a sample Bash script:
#!/bin/bash
# Update server packages
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y && sudo apt-get autoclean
# Check memory and add swap if less than 150MB free (optional)
available_memory=$(free -m | awk '/^Mem:/{print $7}')
if [ "$available_memory" -lt 150 ]; then
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
fi
# Update Ghost-CLI
sudo npm install -g ghost-cli@latest
# Update each Ghost instance
for dir in /var/www/ghost/*/; do
cd "$dir"
ghost update
done
# Check Ghost status
ghost ls
# Optionally reboot if required
echo "Maintenance completed. If required, reboot the server with 'sudo reboot'."
You can save this script as ghost_maintenance.sh, make it executable, and run it as needed:
chmod +x ghost_maintenance.sh
sudo ./ghost_maintenance.sh