/ raspberry pi

Install and run Ghost on a Raspberry Pi

Update - 22 January 2018:

Further to the update on 15 August 2017 below, it is now possible to install Ghost 1.x on Raspbian, so take a look at the latest install guide to get up and running in no time.

Update - 15 August 2017:

If you are looking to install Ghost v1.0.0 and above on Raspberry Pi, take a look at my latest post for the initial steps. The following steps below highlights how to install Ghost v0.11.0 and below on Raspberry Pi.

Install Ghost on Raspberry Pi (v0.11.0)

Ghost is a relatively new blogging platform, that is lightweight and easy to use. Whilst I'm not reinventing the wheel here, I have found that installing and running Ghost on a Raspberry Pi a little tricky, especially when it comes to using your own domain name and a DDNS service like Cloudflare. I've been inspired by other blogs that document various Ghost installations on Raspberry Pi, such as Alex Ellis' fantastic Docker themed blog, but I wanted to keep things simple for those of you, who like me, wanted to install Ghost on your Raspberry Pi manually.

To begin, we'll be looking at how to install Ghost on a Raspberry Pi and then we'll cover how to use your custom domain name via Cloudflare in the next post.

What you'll need

To install and run Ghost on a Raspberry Pi, you'll need:

  1. A Raspberry Pi (2 or 3 actually, this blog is running on a Model B now!)
  2. Micro SD card (16GB or larger)
  3. Suitable power supply (5V, 2A)
  4. Ethernet cable (more reliable than Wi-Fi)

That's it! The parts list is pretty small - obviously, you may want to keep your Raspberry Pi inside a case, but that's optional. I do recommend hard-wiring your Pi to your network, especially as you'll be hosting a blog as a result, as this is much more reliable than Wi-Fi.


Prepare your Pi

Begin by using the latest version of Raspbian Lite and create a fresh SD card using your preferred disk imaging software - i.e. Etcher or Win32DiskImager. We'll be using Raspbian Lite because it makes it easier for us to install Node afterwards as it is not included in the Lite version of Raspbian.

Now ensure you update your software on the Pi:

[email protected] ~ $ sudo apt-get update && sudo apt-get upgrade

Once that has completed, do a little housekeeping on the Pi to remove unused dependencies and then removes any leftover files in the update repositories:

[email protected] ~ $ sudo apt-get autoremove && sudo apt-get autoclean

Lastly, ensure that you expand the filesystem on your Pi to use all of your SD card's capacity:

[email protected] ~ $ sudo raspi-config

Then choose option 1:

1 Expand Filesystem - Ensures that all of the SD card storage is available to the OS

Finish off by rebooting the Pi:

[email protected] ~ $ sudo reboot now

Now we can move onto the next part.


Install Node.js v4.2.4 / v4.8.0 v6.9.5

Now this part really stumped me when I was following other guides on "How to Install Ghost on Raspberry Pi" as they all seemed to focus on installing the latest version of Node.js, which caused me a number of headaches when I was trying to install Ghost.

To get Ghost up and running on your Raspberry Pi, you'll need to install a specific version of Node.js - v4.2.4 UPDATE: Thanks to GainfulShrimp, who pointed out that you can use v4.8.0, I have now updated this post to reflect this - as this is one of the versions that Ghost themselves recommend.

UPDATE - 15 August 2017: You can now use an even newer version of Node.js to run Ghost on Raspberry Pi, so this guide has now been updated to reflect the use of v6.9.5 as this is the LTS version for using Ghost on Raspberry Pi.

Essentially, you can use any of the 27 versions from v4.2.0 through to v4.8.0 and Ghost will work fine on your Raspberry Pi. I now highly recommend using v6.9.5, but I've been fine using v4.2.0 and v4.8.0.

Thankfully, this is a simple process if you use Raspbian Lite as this lightweight version of Raspbian does not have any version of Node.js installed.

For Raspberry Pi Model B

The Raspberry Pi Model B uses ARM6, so we need to download the appropriate version Node.js using the commands below:

[email protected] ~ $ wget https://nodejs.org/download/release/v6.9.5/node-v6.9.5-linux-armv6l.tar.gz
[email protected] ~ $ sudo mv node-v6.9.5-linux-armv6l.tar.gz /opt
[email protected] ~ $ cd /opt
[email protected] ~ $ sudo tar -xzf node-v6.9.5-linux-armv6l.tar.gz
[email protected] ~ $ sudo mv node-v6.9.5-linux-armv6l nodejs
[email protected] ~ $ sudo rm node-v6.9.5-linux-armv6l.tar.gz
[email protected] ~ $ sudo ln -s /opt/nodejs/bin/node /usr/bin/node
[email protected] ~ $ sudo ln -s /opt/nodejs/bin/npm /usr/bin/npm

For Raspberry Pi 2 or 3

The Raspberry Pi 2 or 3 uses ARM7, so we need to download the appropriate version Node.js using the commands below:

[email protected] ~ $ wget https://nodejs.org/download/release/v6.9.5/node-v6.9.5-linux-armv7l.tar.gz
[email protected] ~ $ sudo mv node-v6.9.5-linux-armv7l.tar.gz /opt
[email protected] ~ $ cd /opt
[email protected] ~ $ sudo tar -xzf node-v6.9.5-linux-armv7l.tar.gz
[email protected] ~ $ sudo mv node-v6.9.5-linux-armv7l nodejs
[email protected] ~ $ sudo rm node-v6.9.5-linux-armv7l.tar.gz
[email protected] ~ $ sudo ln -s /opt/nodejs/bin/node /usr/bin/node
[email protected] ~ $ sudo ln -s /opt/nodejs/bin/npm /usr/bin/npm

The above commands will download Node.js version 4.2.4 / 4.8.0 6.9.5, move the tar file to the opt directory, extract the contents of the tar file, move the extracted files to the nodejs directory, remove the leftover tar file then create symbolic links between the relevant node and npm directories.

Once you've that, check that Node.js is installed by running:

[email protected] ~ $ node -v
[email protected] ~ $ v6.9.5

All being well, you should now see v4.2.4 / v4.8.0 v6.9.5 in the terminal. Hurrah! At this point, it might be worth rebooting your Pi just for good measure:

[email protected] ~ $ sudo reboot now

Install Ghost

You'll need to download the latest version of Ghost via the command line on your Pi. This might look daunting, but it's really simple:

[email protected] ~ $ cd ~
[email protected] ~ $ wget https://ghost.org/zip/ghost-latest.zip

This will change you to your home directory and then grab the latest version of Ghost in a zip file directly from Ghost itself. We'll now be unzipping this to a specific location - it doesn't have to be here, but I recommend it. Let's create the directories first:

[email protected] ~ $ sudo mkdir /var/www
[email protected] ~ $ sudo mkdir /var/www/ghost

Now we'll unzip the Ghost files to the newly created directory:

[email protected] ~ $ sudo unzip -d /var/www/ghost ghost-latest.zip

We'll need to use the sudo command as the Pi user doesn't have write access to the /var/www/ghost directory, but we can change that by changing the ownership of the directory and its contents with:

[email protected] ~ $ cd /var
[email protected] ~ $ sudo chown -R pi:pi www/

Now change to the new directory we just unzipped the Ghost files to:

[email protected] ~ $ cd /var/www/ghost

The next stage is to install Ghost, which is done using the following simple command:

[email protected] ~ $ npm install --production

This may take a few minutes, so now is a great time to stretch your legs, rest your eyes and get a drink.

Once the installation is complete, you'll be returned to the command line (hopefully without any errors) and then we can start configuring Ghost - after all, we don't just want to host Ghost on our Raspberry Pi without making it our own do we?

First, we need to create a configuration file for Ghost to use. Luckily, there is an example already in our Ghost installation directory, but we just need to copy this:

[email protected] ~ $ cp config.example.js config.js

This command tells your Pi to copy the config.example.js file to a new file called config.js. Now at this point, I had to change a setting in this new configuration file so that I could open up my new Ghost blog in a browser:

[email protected] ~ $ nano config.js

The part you'll need to change is:

server: {
    host: '127.0.0.1',
    port: '2368'
}

To (replacing 127.0.0.1 with your Pi's IP address):

server: {
    host: '192.168.x.x',
    port: '2368'
}

Ctrl+X and Y to save and exit.


Start Ghost

Before diving into configuring our Ghost blog, let's just be sure it works first! This can save a lot of headaches further down the line, as if it doesn't work here, then something went wrong with the install, and not as a result of something you did when configuring Ghost!

Whilst in the /var/www/ghost directory, run the following command to start Ghost in production mode:

[email protected] ~ $ npm start --production

If all goes well, you should see a lot of activity on the command line, which should end with something like:

[email protected] ~ $ Listening on 192.168.x.x:2368
[email protected] ~ $ Url configured as: http://my-ghost-blog.com
[email protected] ~ $ Ctrl+C to shut down

Now before you shutdown the blog, test it works by going to http://192.168.x.x:2368 in your browser. If all goes well, you should see your Ghost blog!


Next steps

Now that your Ghost blog is up and running on your Raspberry Pi, you can begin the next steps and configure it to your liking. But first, why not get familiar with how Ghost works? For instance, did you know you can log in by browsing to http://192.168.x.x:2368/ghost, but the first time you do this, you'll be asked to create an account?

In the next guide, we'll be covering the more granular parts of configuring Ghost, including using a custom domain name and using Cloudflare DDNS to provide some protection to our Raspberry Pi Ghost Server, so subscribe below and be notified when this is live.


If you found this guide, as well as any other guides on Ghost Pi helpful, then if you wanted to buy Ghost Pi a coffee to show your support, then that would be greatly appreciated! As this site does not use any form of adverts, all the costs for running and maintaining the blog are done voluntarily so any extra would be fantastic!

Buy Me A Coffee
Wesley Archer

Wesley Archer

Digital Account Manager by day, and maker in his spare time. Also, a regular contributor to The MagPi Magazine for the Raspberry Pi Foundation.

Read More