一、下载安装包
# 安装包的地址可在这里查看:https://npm.taobao.org/mirrors/node
# 也可以在官网自行查找:https://nodejs.org
wget http://npm.taobao.org/mirrors/node/latest-v14.x/node-v14.0.0-linux-x64.tar.xz
二、解压
# 压缩包解压即可使用,解压位置请自行选择
# 我这里选择:/usr/local
cd /usr/local
tar -xvf node-v14.0.0-linux-x64.tar.xz
rm -rf node-v14.0.0-linux-x64.tar.xz
三、设置快捷命令
# 先备份一下之前的,没有可以忽略
mv /usr/local/bin/node /usr/local/bin/node.bak
mv /usr/local/bin/npm /usr/local/bin/npm.bak
# 定义软连接到bin下,即可在任何地方使用node
ln -s /usr/local/node-v14.0.0-linux-x64/bin/node /usr/local/bin/node
ln -s /usr/local/node-v14.0.0-linux-x64/bin/npm /usr/local/bin/npm
四、测试
[root@localhost bin]# node
Welcome to Node.js v14.0.0.
Type ".help" for more information.
>
[root@localhost bin]# npm
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@6.14.4 /usr/local/node-v14.0.0-linux-x64/lib/node_modules/npm
五、加速npm
# 安装淘宝的cnpm代替npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 查看版本
[root@localhost /]# cnpm -v
cnpm@6.1.1 (/usr/local/lib/node_modules/cnpm/lib/parse_argv.js)
npm@6.14.2 (/usr/local/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@14.0.0 (/usr/local/node-v14.0.0-linux-x64/bin/node)
npminstall@3.27.0 (/usr/local/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/usr/local/node-v14.0.0-linux-x64
linux x64 3.10.0-1062.9.1.el7.x86_64
registry=https://r.npm.taobao.org
六、版本管理
# nodejs 使用 n 模块进行nodejs的版本
# 我们首先安装n模块
cnpm install -g n
# 列出所有的版本,键盘上下键可切换版本
n
# 安装最新版本
n latest
# 安装最新稳定版
n stable
# 安装最新长期支持版本
n lts