不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2023-10-15 13:25:45  修改时间:2024-05-09 18:39:13  分类:前端/Vue/Node.js  编辑

当前环境:

  • 系统:macOS Ventura
  • 版本:13.4.1

一、安装Git:

Mac安装 Git v2.xBinary installer:下载.dmg文件安装的)

二、安装nvm    【github地址:https://github.com/nvm-sh/nvm

打开终端,执行如下命令

cd ~
git clone https://github.com/nvm-sh/nvm.git .nvm
cd ~/.nvm
#切换至最新版本分支
git checkout v0.39.5
#激活脚本nvm.sh
. ./nvm.sh

在文件~/.zshrc中追加如下脚本:

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

将来手动升级 nvm

  1. change to the ~/.nvm
  2. pull down the latest changes
  3. check out the latest version
  4. activate the new version
(
  cd ~/.nvm
  git fetch --tags origin
  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "~/.nvm/nvm.sh"

三、查看版本

$ nvm --version  
0.39.5

四、配置nvm

(1) 配置 nodejs 淘宝镜像

找到文件~/.zshrc,追加如下配置信息:

# nodejs淘宝镜像
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/

(2) 配置 npm 淘宝镜像

找到文件~/.npmrc,追加如下配置信息:

registry=https://registry.npm.taobao.org/

五、使用nvm安装node

(1) 要下载、编译和安装最新版本的node,请执行以下操作:

nvm install node # "node" is an alias for the latest version

(2) 安装指定版本的node:

nvm install 14.21.3    # or 16.3.0, 12.22.1, etc

安装的第一个版本将成为默认版本。新的shell将以node的默认版本启动(例如,nvm别名default)。

(3) 使用ls-remote列出远程可用(可安装)的版本:

nvm ls-remote

(4) 查看本地已安装的版本

nvm list

(5) 使用已安装的某个版本:

nvm use 14.21.3

(6) 获取node可执行文件的安装路径:

nvm which 14.21.3

(7)显示当前正在使用的node版本

nvm current

(8)卸载指定版本的node

nvm uninstall [version]