#Install the lasted version of nodejs
cd ~
curl -sL https://deb.nodesource.com/setup_18.x -o /tmp/nodesource_setup.sh
If you want to edit it, you can run:
nano /tmp/nodesource_setup.sh
Run the following cmd:
sudo bash /tmp/nodesource_setup.sh
Install the nodejs
sudo apt install nodejs
After finished install, check the version of node and npm
node -v
npm -v
npm fund
#Install Hexo
Run the following cmd:
npm install -g hexo-cli
Create one local folder for you web site
mdkir ~/my_blog
Init the hexo for your web site
hexo init ~/my_blog
Install node_moudles
cd ~/my_blog
npm install
You will get the follow folder:
node_modules: node依赖包
public: 存放生成的页面
scaffolds: 生成文章的一些模板
source: 存放文章
themes: 主题
_config.yml: 博客的配置文件
Start the hexo server:
hexo clean #清理静态文件和缓存数据
hexo new "新文章"
hexo g #生成静态数据(按日期归类的文件夹/html等)
hexo s #本地启动hexo
Install the deploy plugin:
npm install hexo-deployer-git --save
Modify the config file:
vim _config.yml
deploy:
type: git
repo: https://github.com/xxxx/xxx.github.io.git
branch: master
Commit the blog to git:
git init #初始化项目文件夹
git add . #将所有文件添加到暂存区
git commit -m "first commit" #提交到本地仓库,双引号内是提交的备注信息
git remote add origin https://github.com/chaoyangya/chaoyangya.github.io.git
git pull #拉取远程主分支信息,首次拉取合并信息
git push -u -f origin master #提交到远程仓库,这个命令中的 -f 是强制推送,因为远程仓库只有初始化的文件,所以强制推送上去就行了,不加-f 会报当前分支没有远程分支,强制推送可以覆盖master,这样就完成了第一次提交的步骤)
Run deplay cmd:
hexo d -g
Deploy to Netlify
#Fix related errors
Error:
Error: listen EADDRINUSE: address already in use :::4000
The default port of hexo server is 4000, maybe you have started one hexo server before that, so check which program uses it.
sudo lsof -i:4000 # 冒号后面填写端口号
kill the pid
sudo kill -9 pid