centos7安裝NodeJs


一、下載安裝包

# 安裝包的地址可在這里查看: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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM