在 Mac ARM 架构上使用 nvm 安装 Node.js 版本 16.20.2

文章目录

      • [1. 安装 nvm(如果还没有安装的话)](#1. 安装 nvm(如果还没有安装的话))
      • [2. 加载 nvm 配置](#2. 加载 nvm 配置)
      • [3. 列出特定系列的 Node.js 版本(远程):](#3. 列出特定系列的 Node.js 版本(远程):)
      • [4. 安装 Node.js 16.20.2](#4. 安装 Node.js 16.20.2)
      • [5. 使用指定版本的 Node.js](#5. 使用指定版本的 Node.js)
      • [6. 验证安装](#6. 验证安装)

在 Mac ARM 架构上使用 nvm 安装 Node.js 版本 16.20.2,你可以按照以下步骤操作:

1. 安装 nvm(如果还没有安装的话)

在终端中运行以下命令来安装 nvm:

bash 复制代码
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
shell 复制代码
dgq@dgqdeMacBook-Pro ~ % curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16563  100 16563    0     0  20527      0 --:--:-- --:--:-- --:--:-- 20524
You may be on a Mac, and need to install the Xcode Command Line Developer Tools.
If so, run `xcode-select --install` and try again. If not, please report this!
shell 复制代码
dgq@dgqdeMacBook-Pro ~ % xcode-select --install

xcode-select: note: install requested for command line developer tools
shell 复制代码
dgq@dgqdeMacBook-Pro ~ % curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16563  100 16563    0     0  24655      0 --:--:-- --:--:-- --:--:-- 24647
=> nvm is already installed in /Users/dgq/.nvm, trying to update using git
=> * (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

=> Appending nvm source string to /Users/dgq/.zshrc
=> Appending bash_completion source string to /Users/dgq/.zshrc
=> 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

2. 加载 nvm 配置

安装完成后,你需要重新加载 shell 配置文件,以便在终端中使用 nvm 命令。如果你使用的是 zsh,运行:

bash 复制代码
source ~/.zshrc
shell 复制代码
dgq@dgqdeMacBook-Pro ~ % nvm -v
0.40.1

如果你使用 bash,运行:

bash 复制代码
source ~/.bash_profile

3. 列出特定系列的 Node.js 版本(远程):

shell 复制代码
dgq@dgqdeMacBook-Pro ~ % nvm ls-remote | grep v16.
        v16.0.0
        v16.1.0
        v16.2.0
        v16.3.0
        v16.4.0
        v16.4.1
        v16.4.2
        v16.5.0
        v16.6.0
        v16.6.1
        v16.6.2
        v16.7.0
        v16.8.0
        v16.9.0
        v16.9.1
       v16.10.0
       v16.11.0
       v16.11.1
       v16.12.0
       v16.13.0   (LTS: Gallium)
       v16.13.1   (LTS: Gallium)
       v16.13.2   (LTS: Gallium)
       v16.14.0   (LTS: Gallium)
       v16.14.1   (LTS: Gallium)
       v16.14.2   (LTS: Gallium)
       v16.15.0   (LTS: Gallium)
       v16.15.1   (LTS: Gallium)
       v16.16.0   (LTS: Gallium)
       v16.17.0   (LTS: Gallium)
       v16.17.1   (LTS: Gallium)
       v16.18.0   (LTS: Gallium)
       v16.18.1   (LTS: Gallium)
       v16.19.0   (LTS: Gallium)
       v16.19.1   (LTS: Gallium)
       v16.20.0   (LTS: Gallium)
       v16.20.1   (LTS: Gallium)
       v16.20.2   (Latest LTS: Gallium)

4. 安装 Node.js 16.20.2

使用 nvm 安装指定的 Node.js 版本(16.20.2):

shell 复制代码
dgq@dgqdeMacBook-Pro ~ % nvm install 16
Downloading and installing node v16.20.2...
Downloading https://nodejs.org/dist/v16.20.2/node-v16.20.2-darwin-arm64.tar.xz...
########################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.20.2 (npm v8.19.4)
Creating default alias: default -> 16 (-> v16.20.2)
bash 复制代码
nvm install 16.20.2

5. 使用指定版本的 Node.js

安装完成后,可以使用以下命令来切换到该版本:

bash 复制代码
nvm use 16.20.2

6. 验证安装

检查 Node.js 是否安装成功:

bash 复制代码
node -v
shell 复制代码
dgq@dgqdeMacBook-Pro ~ % node -v
v16.20.2
shell 复制代码
dgq@dgqdeMacBook-Pro ~ % corepack -v
0.17.0

这应该会输出 v16.20.2,表示安装成功。

这样,你就可以在 Mac ARM 架构上通过 nvm 安装并使用 Node.js 16.20.2 了!

相关推荐
程序员爱钓鱼4 分钟前
Node.js 编程实战:理解 Buffer 与 Stream
后端·node.js·trae
Mac技巧大咖24 分钟前
Mac误删文件,废纸篓也清了?Mac时光机器仍可恢复找回
macos·mac误删文件
程序员爱钓鱼2 小时前
Node.js 编程实战:npm和yarn基础使用
后端·node.js·trae
程序员爱钓鱼2 小时前
Node.js 编程实战:CommonJS 与ES6 模块
后端·node.js·trae
程序员果子2 小时前
零拷贝:程序性能加速的终极奥秘
linux·运维·nginx·macos·缓存·centos
天庭鸡腿哥2 小时前
macOS的功能,在Windows上也能实现
windows·microsoft·macos·visual studio·everything
weixin_462446233 小时前
macOS 安装 git-lfs
git·macos
孟祥_成都6 小时前
nest.js / hono.js 一起学!hono的设计思想!
前端·node.js
星空椰6 小时前
Windows 使用nvm多版本管理node.js
windows·node.js
我叫唧唧波7 小时前
【自动化部署】基于Docker构建CI/CD流水线
ci/cd·docker·node.js