ubuntu安装最新版nodejs,以及安装hexo

第一步,去 nodejs 官网 https://nodejs.org 看最新的版本号;

写本笔记时的最新版本是14.x.x

第二步,添加源后安装

1
2
3
4
5
6
7
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
## 注意如果版本是16.15.2的话,就写setup_16.x
sudo apt update
sudo apt install nodejs
# 或者以下办法也可以安装
wget -qO - https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt-get install -qqy nodejs

安装完成后查看版本

1
node -v

对npm进行镜像加速

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 一、淘宝镜像源
npm config set registry https://registry.npm.taobao.org
# 验证
npm config get registry
# 返回https://registry.npm.taobao.org,成功。

# 二、华为云镜像源
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
# 验证
npm config get registry

# 三 通过使用淘宝cnpm安装
# 1. 安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 2. 使用cnpm
cnpm install xxx

# 四. 取消镜像加速
npm config set registry https://registry.npmjs.org/

·

安装hexo

1
2
3
4
5
6
7
8
9
$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
$ sudo cnpm install hexo-cli -g
$ sudo apt install git # 如果没有安装,在安装hexo会出错
$ hexo init myblog # 初始化目录
$ cd myblog
$ npm install
$ apt install openssl #如果要部署到github或gitee,则必须装
$ npm install hexo-deployer-git --save #如果要部署到github或gitee,则必须装
$ hexo s -p 80 强制为80端口