How to install Ghost blog on Ubuntu

How to install Ghost blog on Ubuntu

Recently, I migrated This Dev Brain and Brain Archives to new VPSs. In both cases, I had to set up the operating systems and install Ghost from scratch. As a result, I've prepared this concise set of instructions in case I need to do this again.

Configure Ubuntu

Add user

Create a new user:

adduser ghostuser

Add user to superuser group to unlock admin privileges:

usermod -aG sudo ghostuser

Log in as the new user:

su - ghostuser

Update packages

Update package lists:

sudo apt-get update

Update installed packages:

sudo apt-get upgrade

Install Nginx

Install Nginx package:

sudo apt-get install nginx

Enable Nginx in firewall:

sudo ufw allow 'Nginx Full'

Install Node.js

Download and import the Nodesource GPG key:

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Create deb repository:

NODE_MAJOR=18 # Set latest version that is compatible with Ghost
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg]$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Update and install packages:

sudo apt-get update
sudo apt-get install nodejs -y

Install MySQL

Install MySQL server package:

sudo apt-get install mysql-server

Secure MySQL:

sudo mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] Y
- Remove anonymous users? [Y/n] Y
- Disallow root login remotely? [Y/n] Y
- Remove test database and access to it? [Y/n] Y
- Reload privilege tables now? [Y/n] Y
In some cases the mysql_secure_installation might fail because of authorization error. In that case run sudo mysql and then, in MySQL console, run this command:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'Here_Is_Your_MySQL_Root_User_Password'; Once database is updated, the mysql_secure_installation script should work properly.

Once the MySQL server is configured, start and enable the MySQL service:

sudo systemctl start mysql
sudo systemctl enable mysql

Setup Database

Login to MySQL server:

sudo mysql -u root -p

Create database:


Create user:

CREATE USER 'ghostuser'@'localhost' IDENTIFIED BY 'Here_is_Ghost_User_Password';

Set privileges:

GRANT ALL PRIVILEGES ON ghostdb. * TO 'ghostuser'@'localhost';

Flush privileges:


Close MySQL terminal:


Setup Ghost

Ghost CLI

Install Ghost CLI:

sudo npm install ghost-cli@latest -g

Setup folder with the site

Create directory. Change sitename to name of your website:

sudo mkdir -p /var/www/<sitename>

Set directory owner. Replace ghostuser with the name of the user created at the very beginning of this article:

sudo chown ghostuser:ghostuser /var/www/<sitename>

Set the correct permissions

sudo chmod 775 /var/www/<sitename>

Then navigate into it:

cd /var/www/<sitename>

Ghost Blog

Install Ghost Blog:

ghost install

Setup Ghost:

Install questions
? Enter your blog URL:
? Enter your MySQL hostname:
? Enter your MySQL username: ghostuser
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghostdb

Once Ghost Blog is configured, it should start and be ready for further setup at


Anything interesting to share? Write a comment.