Home / Operating System / Linux / How to install Ghost on Ubuntu

How to install Ghost on Ubuntu

Unless you plan to run a hosted Ghost blog, then you surely must learn to install and run it on your own server. Excellent hosting plans are available out there (from which I strongly recommend DigitalOcean or RunKite – they even have a ready-to-run Ghost app!) so the choice is yours. Just make sure you chose someone that allows you to install and configure Nodejs – this is required by Ghost.

I personally run this blog on an Ubuntu 13.04 droplet from DigitalOcean. My every day computer is also running an Ubuntu 13.10 so I’m quite familiar with the environment.

This tutorial will help you install, configure and run Ghost on Ubuntu. I’ve tried to make it as simple as I could so every one can benefit from it.

Note before starting: I highly recommend creating an user under which to run your Ghost installation. After logging on your machine as root, simply issue the following command:

$useradd -d /home/user -m -s /bin/bash user

Replace user with your desired user name.

Unless stated otherwise, all of the commands in this guide are run as root.

Setting up the environment

First thing to do is decide a location under which to install Ghost. In this guide I decided to use /opt/ghost. You can use any location that suits you.

$ mkdir /opt/ghost
$ chown -R /opt/ghost user:user

The last command will change the folder owner to the dedicated user we created for the installation.

Make sure you are up to date with the latest Ubuntu packages. Underroot, run:

$ apt-get update 
$ apt-get upgrade

Now, there are two ways to deploy Ghost. Eigher from release sources (bydownloading the source files and extrating the archive to the desired location) or from GitHub. This guide will deploy the second option (more info on how to install Ghost from GitHub) because I find it more easy to keep up to date with the latest changes.

Installing dependencies

Installing git

Git is a distributed revision control and source code management (SCM) system with an emphasis on speed. This guide is not intended to explain what git is in detail, so take the crash course if you want to find out more.

The following command will install git and all it’s dependencies:

apt-get install git  

Note – this step is not required if you’re deploying from release sources.

Installing Ruby

apt-get install ruby  

Once that is done, you need to install sass and bourbon gems, by running the following:

gem install sass  
gem install bourbon  

Installing Node.js

Ghost is based on Node.js so obviously you’ll need this installed. Just run:

apt-get install nodejs  
apt-get install npm  

This should install the latest available version in the Ubuntu repositories – version 0.10.15 at the time of this guide.

If you’d like a more recent version I suggest adding this PPA and then update your packages. Just remember that Ghost requires Node.js between 0.10.0 and 0.11.3 so don’t overstep it!

Ghost also requires Grunt and SQLite so make sure you have them installed:

npm install -g grunt-cli  
apt-get install sqlite  

Installing nginx

You’ll obviously need a web server to run Ghost. We’ll be using nginx because it’s easy to configure and use.

apt-get install nginx  

This will install nginx in the default path – /etc/nginx. All it needs now is configuring.

We are going to use an nginx best practice and create a config file for your Ghost instance, named ghost – or use whatever you want:

vi /etc/nginx/sites-available/ghost

Copy-paste the following code:

server {  
        listen 80;
        server_name localhost;

        location / {
                proxy_pass http://localhost:2369;
                proxy_set_header Host $host;
                proxy_buffering off;

The above configuration file will tell nginx that any request that comes tohttp://localhost should be redirected to localhost, port 2369. This is where our Ghost instance will listen on.

After saving, make a soft link of this ghost config to sites-enabled and restart nginx:

ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost  
service nginx restart  

If after restaring nginx you get a warning in the lines ofnginx: [warn] conflicting server name "localhost" on, ignored, replace server_name localhost withserver_name <your_ip_address> and restart nginx.

Installing Ghost

Now that we have our web server running, it’s time to get going with Ghost.

Under user, change directory to where you decided to run Ghost from and clone the git repository:

cd /opt/ghost  
git clone git://github.com/TryGhost/Ghost.git .  

It’s important you don’t forget the.  at the end or git will clone the repo by default to a Ghost directory (so you’ll end up with /opt/ghost/Ghost – if you like that leave it that way).

Next, install Ghost! But before that, because there is a conflict betweennodejs and a packaged named node, we need to fool Ubuntu to usenodejs when running node commands:

ln -s /usr/bin/nodejs /usr/bin/node  
which node  

If the output is /usr/bin/node the you’re all good! If not, relog and try again.

Onto really installing Ghost:

cd /opt/ghost  
git submodule update --init  
npm install --production  
grunt init  

Once this is done, it’s time to configure Ghost. Copy the default configuration that comes with Ghost and customize it:

cp config.example.js config.js  
vi config.js  

Find ### Production and replace like below:

// ### Production
    // When running Ghost in the wild, use the production environment
    // Configure your URL and mail settings here
    production: {
        url: 'http://localhost',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            debug: false
        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: 'locahost',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2369'

Starting Ghost

It’s time to finally start Ghost!

cd /opt/ghost  
npm start --production  

Now navigate to http://localhost orhttp://<your_ip_address> and you should see your Ghost blog!

Print Friendly

About dongpolice

Check Also

Xem số điện thoại đang dùng Vinaphone, Mobi, Viettel không cần gọi

Để biết số điện thoại mình đang dùng: – Ở Việt Nam có nhiều nhà …