如何在centos下安装node服务
参考centos 下安装 nodejs 的三种方式 (opens new window),推荐 nvm 方式安装。
curl:
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
1
wget:
$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
1
安装时遇到错误:
错误 1 error: RPC failed; result=35, HTTP code = 0 fatal: The remote end hung up unexpectedly Failed to clone nvm repo. Please report this!
将 https 改为 http 重新安装即可。
错误 2 Error: the install instructions explicitly say to pipe the install script to
bash
; please follow them 安装命令改下$ wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | bash
1
下载后看着正常,但是没有找到 nvm 命令。看下日志记录:
[root@VM-16-11-opencloudos dependencies]# wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | bash
=> Downloading nvm as script to '/root/.nvm'
=> nvm source string already in /root/.bashrc
=> bash_completion source string already in /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
其实已经安装成功了,只需要重新打开终端,或者 source 即可.
source ~/.bashrc
nvm --version
1
2
2
安装完成后,执行下列命令即可安装 Node.js。
$ nvm install v14.18.1
1
查看安装的版本
node -v
# 14.18.1
npm -v
# 6.14.15
1
2
3
4
5
2
3
4
5
上次更新: 2023/06/16, 18:45:32