Build a Hexo personal blog based on Ubuntu

background

        Compared with wordpress, I prefer the simplicity of Hexo, and then I went to find tutorials, and then found that some tutorials would report some errors if I followed them. It may be due to differences in the environment, and then I combined multiple tutorials and various online error reports. I finally set up Hexo, and then sorted it out and posted it. I hope it can be a reference for everyone who wants to build a Hexo personal blog. I want to see the effect first. Welcome to my Hexo blog .

1. Prepare the environment

1. Install Git

sudo apt install git-core -y

2. Install Node.js

wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
source ~/.profile
nvm install stable

2. Install Hexo

1. Install cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org

2. Install Hexo

Create a folder first, then enter the folder to start the installation

mkdir hexo
cd hexo/
cnpm install -g hexo-cli
hexo init 

3. The test installation is successful

Open the Hexo service

hexo server

At this time, open the browser and visit your own [host ip: 4000], and you can see the blog page we built successfully.

But this is only local, and then we can deploy the blog to GitHub and we can access it from the local.

 

3. Deploy the blog to GitHub

1. Register with GitHub

    

If you don't have a GitHub account, go to register a GitHub account first, and if you have a GitHub account, go directly to the next step;

 

2. Set user.name and user.email

After registration, come back to your own machine

git config --global user.name "Your user.name"
git config --global user.email "You user.email"

Replace " " with your own user.name and user.email;

3. Generate shh key

ssh-keygen -t rsa -C user.email

The following prompts to enter the path to save to, we enter

 
 /home/ubuntu/.ssh/id_rsa

Then press Enter directly below;

4. View the shh key

 vim /home/ubuntu/.ssh/id_rsa

Copy the key, and then go to the GitHub account to add the SSH key;

5. Add SSH key to GitHub account

Add ssh key, click send ;

6. Create a GitHub repository

The naming format is "account userName".github.io

For example: zhangsan.github.io

Go to [Create GitHub repository] ( transfer )

7. Modify the hexo configuration file

Go to your own hexo installation directory and open the _config.yml file

Modify the following part;

deploy:
    type: git
    repo: [email protected]:(BoView)/(BoView).github.io.git #括号里面换成自己的用户名和仓库名,去掉括号
    branch: master

8. Deployment

Install the hexo-deployer-git plugin

npm install hexo-deployer-git --save
//生成静态页面
hexo g
//将public文件内容部署到github仓库
hexo d
//这两条是常用的命令,后者也可以这样
hexo d -g
//或者
hexo g -d

 

At this point, you can open a browser to access userName.github.io (GitHub warehouse name)

That is, you can visit the built blog page

The task is basically completed here, but we want to be more perfect, and then bind a domain name, and then use the domain name to access;

Fourth, bind the domain name

1. Add analysis records

 

Go to [Add Analysis] ( Transfer ) under your own domain name

The record type is CNAME, the host record is @ line, the default is selected, the TTL is 600, and the record value is the warehouse name of github userName.github.io

2. Configure hexo

 

Create a CNAME configuration file

touch ~/hexo/source/CNAME

Next, add the domain name just resolved in the CNAME configuration file

For example: zhangsan.com

Then redeploy it,

ok, ok, congratulations everyone,

 

At this time, open the browser and visit your own domain name to access the blog you built

Start your own 【Blog Journey】,

Five, finally

If you encounter any problems, please post them and discuss them together. If there is something not clear enough or something is wrong, please add it! ! !

You are welcome to visit my Hexo blog to see the final result.
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Gage__/article/details/80302471