In the post titled Installing Ghost and Nginx on Ubuntu Server LTS, I covered how to install Ghost and Nginx on Ubuntu server from scratch.

Once you have a Ghost server running, you'll inevitably find yourself needing to perform an in-place upgrade. The team responsible for maintaining Ghost updates the blogging platform often. You'll want to keep your instance of Ghost current to correct bugs, avoid security issues, and to take advantage of newly added features. You can keep informed of the Ghost development team's efforts and roadmap by periodically visiting their development blog or participating in Ghost's public development meetings.

Fortunately, the Ghost team has made in-place upgrades fairly seamless, fast, and reliable. In-place Ghost upgrades should keep all of your blog content and settings while replacing the core engine that powers Ghost. After you have upgraded Ghost a few times, this process will become second nature and only requires a few simple steps.

How to check if a Ghost server instance is out of date?

There are several ways to verify whether your Ghost server is current. By far the easiest way to do this is from the About Ghost page that is accessible by Ghost administrators. After logging into Ghost as a user with administrative privileges, you can reach this page by directly accessing the URL: http://youserver.com/ghost/about/ . Alternatively, under your username, there will be a down arrow that allows you to access the about screen as well as a few other user account options:

About Ghost contextual menu

Once you have loaded the About Ghost page, it will list the version number that is currently installed. Additionally, if a newer version is available, you should see red text indicating that a newer version is available:

About Ghost page mentioning that a software update is available

If a newer version is available, Ghost will provide a link to a page that includes installation instructions which are very similar to those included here. As mentioned in the Ghost upgrade guide, it is not recommended to upgrade from a version of Ghost less than .5.xxx to 0.11.1 directly before to upgrading to .7.xxx . The reason for this is that the Ghost team has dropped support for upgrading from very old versions of Ghost to the latest version as there is a development cost for supporting upgrades from these older versions.

Step 1: Backup Ghost

Ghost's upgrade process rarely exhibit any issues. However, it is prudent to backup your valuable blog content. If you have scheduled backups setup for your server, confirm that they are enabled and running without errors. Additionally, if your cloud server provider supports taking snapshots, you may want to consider taking a temporary snapshot prior to upgrading. By having a backup and/or snapshot at a known good prior state, you'll always have the ability to revert back if the upgrade goes terribly wrong.

Ghost also has an export option, which is well documented on Ghost's Import/Export Data Documentation Page. The import/export data feature can be useful at times. I have personally verified that it works quite well. However, it will not export any images you have used within your blog posts. If you plan on using Ghost's import/export data feature, you'll likely also want to regularly backup all blog images added to Ghost's images directory manually. By default, Ghost stores images in the images ghost sub-directory (...ghost/content/images).

Step 1: Get the latest version of Ghost

Via a SSH shell, navigate to the parent directory to where you have installed Ghost. The path /var/www/ghost/ is a typical location where system administrators install Ghost.

Next, download the latest version of Ghost by running Curl with the following arguments:

sudo curl -LOk https://ghost.org/zip/ghost-latest.zip  

Step 2: Unzip the latest version of Ghost to a temporary directory

Once the latest version of Ghost has been downloaded, the zipped file needs to be extracted to a temporary directory by running the following command:

sudo unzip ghost-latest.zip -d ghost-latest  

Verify that the directory was created using the ls command:

ls -a  

Step 3: Delete old core directory files

Now that you have downloaded and extracted the latest version of Ghost, go to the directory that you have installed Ghost to (e.g. cd var/www/ghost) and verify that you are in the correct directory by running the pwd command.

For the upgrade to be successful, you must delete the core directory within the parent ghost directory. You can optionally also delete all .js, .md, and .json files other than config.js. You do not want to delete config.js as this file contains all of your customized configuration settings for Ghost. Deleting the .js, .md, and .json files is an unnecessary step since these files will be overwritten when we copy the newer Ghost files over in a later step, but it will not harm anything either.

Delete the core directory by executing the following command:

sudo rm -rf core  

Step 4: Copy new files

The next step is to selectively copy the new files from the unzipped ghost-latest directory you made from Step 2 to the directory where you installed Ghost. Assuming you have installed Ghost at var/www/ghost and you have unzipped ghost-latest to var/www/ghost-latest this can be accomplished by running the next series of commands.

Change your current directory to var/www/:

cd var/www/  

Recursively copy the latest core files from var/www/ghost-latest/content to var/www/ghost/content:

sudo cp -R ghost-latest/core/ ghost/  

Recursively copy the latest Casper theme files from var/www/ghost-latest/content/themes/casper to var/www/ghost/content/themes/casper:

sudo cp -R ghost-latest/content/themes/casper  ghost/content/themes  

Copy all .js, .json, and .md files from var/www/ghost-latest/ to var/www/ghost/
cp *.js *.json *.md LICENSE ~/ghost:

sudo cp ghost-latest/*.md ghost  
sudo cp ghost-latest/*.js ghost  
sudo cp ghost-latest/*.json ghost  

Assuming you have created a user non-privileged user account for running Ghost as a service (e.g. a user account named ghost), give that user account ownership of the recently copied and modified Ghost configuration files:

cd /var/www/  
sudo chown -R ghost:ghost ghost/*  

Step 5: Update NPM dependencies

Now change your current directory to the directory in which Ghost is installed (typically cd /var/www/ghost/)

Run the following command to update Ghost's dependencies:

sudo npm install --production  

Running this command may take several minutes to complete. It's normal to see a text-base progress indicator (pound signs indicate progress).

If NPM was successful, you shouldn't see any red error messages (warnings are ok). Additionally, you should see that NPM printed a textual tree-based dependency graph in your shell window. If NPM's dependency update was unsuccessful, a new log file named `npm-debug.log should be created with information regarding the error(s).

A suggested first troubleshooting step is to delete the ghost sub-directory node_modules and then run command npm cache clean before attempting to update dependencies again:

sudo rm -rf node_modules  
sudo npm cache clean  
sudo npm install --production  

Another common problem occurs when users attempt to run npm without using the sudo command or without root privileges.

Step 6: Restart Ghost

Now, restart Ghost by running the following command:

sudo service ghost restart  

At this point, hopefully Ghost is up and running again at the latest version. You can confirm that Ghost is running properly and has been fully upgraded by verifying the version number of Ghost listed on the About Ghost page.

Step 7: (Optional) Install Server Updates

While not required, this may be a good time to also ensure that your server is up to date and patched for any security updates. Assuming you are running Ubuntu Server, you can do this by running the following series of commands:

Get available update listing

Use the apt-get update command to update the listing of available updates as follows:

sudo apt-get update  
Upgrade installed packages

The apt-get update command installs all available packages:

sudo apt-get upgrade  

If no new/updated packages are available you'll see the following message:

Reading package lists... Done  
Building dependency tree  
Reading state information... Done  
Calculating upgrade... Done  
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.  
Remove unused packages

You will want to occasionally run the apt-getautoclean command in order to remove any .deb packages that are no longer referenced by or installed on your system from from /var/cache/apt/archives. This command can potentially free up unused space on your server and can be ran as follows:

sudo apt-get autoclean  
Upgrade Ubuntu Server

To upgrade Ubuntu Server itself, you can use the following command:

do-release-upgrade