Mac OS 下 NVM的安装和使用

1、查看~/.bash_profile目录文件是否存在

cd ~

显示这个目录下的所有文件,(包含隐藏文件)

ls -a 

查看.bash_profile文件是否存在,

如果没有,新建一个:

touch ~/.bash_profile

2、安装

官网:https://github.com/nvm-sh/nvm 查找关键字:Install

会发现如下内容

Install & Update script

To install or update nvm, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh

执行上述任意一条命令

3、检查~/.bash_profile文件中的nvm环境变量是否生成:

cat ~/.bash_profile

内容如下:

[ -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

4、重新打开窗口,执行nvm,看命令是否生效.

5、nvm 不生效?

  • 1、执行source ~/.bash_profile
  • 2、如果使用了zsh
    • vim ~/.zshrc
    • 将source ~/.bash_profile添加进去

6、如何使用

详细的在https://github.com/nvm-sh/nvm
网页中搜索 Usage

安装最新版本:
To download, compile, and install the latest release of node, do this:

nvm install node 

安装指定版本:
"node" is an alias for the latest version,To install a specific version of node:

nvm install 6.14.4 # or 10.10.0, 8.9.1, etc

查看node版本

nvm ls-remote # 远端版本
nvm ls #本地已安装的版本

使用

nvm use node # 使用最新版本
nvm use 12.13.0 # 使用指定版本

查看node版本安装位置

nvm which 5.0
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。