安装NVM和Node.js
环境
Oracle Linux 7.5
Git 1.8.3.1(Oracle Linux 7自带)
NVM 0.35
Node.js 12.13.0
简介
NVM=Node Version Manager,NVM依赖于Git,Oracle Linux 7.5自带Git,建议使用NVM安装和管理node.js
安装NVM
自动安装
下载及文档见 Link
安装运行1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
或
1 | wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash |
安装命令运行如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21[root@ol75elk74s ~]# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:-- 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--100 13527 100 13527 0 0 17504 0 --:--:-- --:--:-- --:--:-- 17522
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
remote: Enumerating objects: 286, done.
remote: Counting objects: 100% (286/286), done.
remote: Compressing objects: 100% (256/256), done.
remote: Total 286 (delta 34), reused 93 (delta 17), pack-reused 0
Receiving objects: 100% (286/286), 146.90 KiB | 7.00 KiB/s, done.
Resolving deltas: 100% (34/34), done.
=> Compressing and cleaning up git repository
=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /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 | [root@ol75elk74s ~]# nvm --version |
通过git安装
下载1
2cd ~
git clone https://github.com/nvm-sh/nvm.git .nvm
激活nvm1
2cd ~/.nvm
. nvm.sh
NVM环境变量
如果是以root用户安装,默认被修改的配置文件如下表
操作系统 | 运行的用户 | 相对安装路径 | 实际安装路径 | 说明 |
---|---|---|---|---|
Oracle Linux 7.5 | root | ~/.nvm | /root/.nvm | 安装目录 |
Oracle Linux 7.5 | root | ~/.bash_profile, ~/.zshrc, ~/.profile, 或 ~/.bashrc | /root/.bashrc | 配置文件 |
~/.bashrc即/root/.bashrc会被添加如下环境变量1
2
3export 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
安装Node.js
查看所有可用的node.js版本1
nvm ls-remote
安装最新版的node.js1
nvm install node
安装指定版本的node.js1
nvm install 12.13.0
查看某版本node.js的安装目录1
nvm which 12.13.0
History
v1.0,2019.10.22,初始版本
v1.1,2020.01.30,添加git安装方式
本文作者 : Shen Peng
原文链接 : http://yoursite.com/2019/10/22/安装NVM和Node-js/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
知识 & 情怀 | 二者兼得