Rabi Kavoori

Principal Software Engineer
Works at Oath:
(which acquired Millennial Media)
(which acquired Nexage)
Lives in Atlanta, GA

TwitterGitHubRSS


About

Java developer, currently into Scala, likes to tinker, tries to solve all problems in life by writing code and loves the great indoors!

Installing Hexo on Ubuntu

[   Blog   ]            

I have been searching for a simple and lightweight self hosted blogging platform that is suitable for programmers and I might have found the one! Hexo.

Here is a 10 minute installation to get it up and running.

The only requirements are :

1. Install Node.js

The best way to install Node.js is installing with nvm.

curl https://raw.githubusercontent.com/creationix/nvm/v0.17.2/install.sh | bash

The above script clones the nvm repository and also adds the source line to ~.bashrc (or ~/.bash_profile or ~/.profile)

Run the following to get a list of all the Node.js versions available and choose the version to install

nvm ls-remote

Install the version you have chosen by running the following:

nvm install 0.11.14

2. Install Git

Ubuntu should have git already installed, but if it is not, run:

sudo apt-get install git-core

3. Install Hexo.

Use npm to install the hexo package globally (using the -g flag)

npm install -g hexo

4. Create a blog

Initialize a blog folder and install all dependencies.

hexo init blog
cd blog
npm install

5. Configure

Modify the options in _config.yml file which should be in the folder created by hex init command. The following configuration options are of interest.

title: [Blog Title]
subtitle: [Sub Title]
description:
author: [Name]
email:
language: [IETF format]

port: [port number]
server_ip: [ip address to bind]
logger: true
logger_format: default

6. Start Hexo server

Start the hexo server by running the following:

hexo server

This will start the server at the IP address and port specified in _config.yml file.

7. Installing a theme

The themes are installed under themes directory which is under the root directory (which is blog in this case) To install a theme like light do the following:

git clone https://github.com/hexojs/hexo-theme-light.git themes/light
cd themes/light
git pull

Edit the _config.yml to include the name of the theme to light as follows:

theme: light

8.Use forever to start and stop the server

Install forever globally.

npm install -g forever

Install hexo in the blog folder.

npm install hexo --save

Create a app.js file under blog directory as follows:

require('hexo').init({command: 'server'});

Now you can use forever to start and stop the server as follows

forever start app.js
forever stop app.js
forever restart app.js

9.Deploy to Github pages by editing the configuration file

deploy:
  type: github
  repo : git@github.com:[reponame] # usually username/username.github.io
  branch: master

Generate the site and deploy at the same time using:

hexo generate --deploy

For further documentation see the Hexo Documentation.

Pro tip - if you are monkeying about with different Hexo themes, make sure you delete the db.json file in the root folder before you generate/deploy. I’m not sure what that thing is, but some theme garbage can get jammed up in there and it won’t show up running hexo server but it will maddeningly appear when you generate the site.

comments powered by Disqus