How to Build and Deploy a Hexo Blog on GitHub Pages Using CentOS
This step‑by‑step guide shows how to set up a personal blog on a CentOS 7.7 server with Hexo, configure Git, SSH keys, and a GitHub repository, then deploy the site to GitHub Pages and optionally bind a custom domain.
Prerequisites
The tutorial assumes a fresh CentOS 7.7 environment.
Install required tools
Install git and verify the version:
yum -y install git
git --versionInstall Node.js (v10.0 or later) and create symbolic links so that node and npm are globally available:
# download Node.js
wget https://nodejs.org/dist/v10.0.0/node-v10.0.0-linux-x64.tar.gz
# extract to /usr/local
tar -zxvf node-v10.0.0-linux-x64.tar.gz -C /usr/local/
# rename folder
mv /usr/local/node-v10.0.0-linux-x64 /usr/local/node-v10.0.0
# verify installation
/usr/local/node-v10.0.0/bin/node -v
# create symlinks
ln -s /usr/local/node-v10.0.0/bin/node /usr/local/bin/node
ln -s /usr/local/node-v10.0.0/bin/npm /usr/local/bin/npmInstall Hexo
With Node.js ready, install the Hexo CLI globally: npm install -g hexo-cli Initialize a new Hexo blog and install dependencies:
hexo init myblog
cd myblog
npm installThe generated myblog directory contains the configuration file _config.yml, package.json, theme folder, and source folders for drafts and posts.
Run the blog locally
Start the development server and preview the site at http://localhost:4000:
hexo serverCreate a GitHub repository
Create a GitHub account if needed, then create a new repository named <username>.github.io. This repository will host the static site.
Configure SSH key
Set global Git user info, generate an SSH key pair, and add the public key to GitHub:
# set user info
git config --global user.name "YourName"
git config --global user.email "[email protected]"
# generate key
ssh-keygen -t rsa -C "[email protected]"
# copy the content of id_rsa.pub and add it in GitHub Settings → SSH and GPG keys → New SSH keyDeploy Hexo to GitHub Pages
Install the deployment plugin, edit _config.yml to add the deploy section, then push the site:
cd myblog
npm install hexo-deployer-git --save
# edit _config.yml and add:
# deploy:
# type: git
# repo: [email protected]:YourUser/YourUser.github.io.git
# branch: master
hexo clean
hexo generate
hexo deployAfter deployment, the blog is accessible at https://YourUser.github.io.
Configure a custom domain (optional)
Purchase a domain, add a CNAME record pointing to yourname.github.io, then set the custom domain in the GitHub repository settings under “Custom domain”.
Publish the first post
Create a new post with hexo new "Post Title", edit the generated Markdown file under source/_posts, then run the clean‑generate‑deploy cycle again to publish.
Conclusion
The guide covers the basic workflow of building a Hexo blog, deploying it to GitHub Pages, and optionally binding a custom domain; further customization such as themes, comments, and analytics can be added later.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
