Welcome to our website.

Setting Up Hexo on GitHub: A Straightforward Deployment Guide

Local environment setup

Before installing Hexo, make sure the basic tools are in place:

  • Install Git: https://git-scm.com/
  • Install Node.js: https://nodejs.org/en/

Install and initialize Hexo locally

Create a folder anywhere on your computer to serve as the blog directory. Inside that folder, right-click and choose Git Bash Here to open the command line.

Run the following commands:

npm install -g hexo-cli
hexo -v
hexo init
hexo s -g

If hexo -v returns version information, the installation worked. After hexo init, a successful setup will display INFO Start blogging with Hexo!, and the necessary files will appear in the folder you created.

To preview the site locally, run hexo s -g. The preview address is localhost:4000. If the page loads correctly, the local blog is ready.

To stop the preview, press Ctrl\+C. After stopping, clear the local cache with:

hexo clean

When the cleanup succeeds, you should see INFO Deleted database.

Prepare GitHub for deployment

GitHub can be used as the hosting platform for the blog.

  1. Log in to GitHub and create a new repository. The repository name must match the owner name, for example XXXX.github.io, where XXX is your owner name.

  2. Bind your Git username and email:

git config --global user.name "name"
git config --global user.email "[email protected]"

Replace name and [email protected] with your own username and email address.

Set up SSH

Generate an SSH key with:

ssh-keygen -t rsa -C “[email protected]

Replace the email with your own. After entering the command, press Enter three times. The .ssh directory will be located in CUsers用户名.ssh.

Open id_rsa.pub inside the .ssh folder with a code editor and copy the key content.

Then add the public key to GitHub:

Settings > SSH and GPG keys > New SSH key

Paste the key into the new SSH key field. A note is optional. Save it when you're done.

To check whether SSH has been added correctly, run:

ssh -T [email protected]

After entering the command, type yes when prompted.

Deploy Hexo to GitHub

Open your local blog directory, find _config.yml, and edit it. Go to the last line, remove the content after deploy:, and add the following:

type: git
repo: [email protected]:xx/xxx.github.io.git
branch: master

Replace the value after repo: with your GitHub SSH address. The deploy: setting must be connected to the block above.

Install the deployment plugin:

npm install hexo-deployer-git --save

After that, deploy the blog with:

hexo d -g

Once this finishes, the Hexo site will be pushed to GitHub.

Related Posts