AdSense

網頁

2024/3/21

Mac 安裝Node Version Manager nvm

MacOS安裝Node的版本管理工具nvm


安裝環境:

  • Apple M1 Pro
  • macOS Ventura 13.0.1


安裝

開啟終端器,輸入curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash開始安裝nvm。

% curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15037  100 15037    0     0  60214      0 --:--:-- --:--:-- --:--:-- 61627
=> Downloading nvm from git to '/Users/user/.nvm'
=> Cloning into '/Users/user/.nvm'...
remote: Enumerating objects: 365, done.
remote: Counting objects: 100% (365/365), done.
remote: Compressing objects: 100% (313/313), done.
remote: Total 365 (delta 43), reused 166 (delta 26), pack-reused 0
Receiving objects: 100% (365/365), 365.08 KiB | 3.02 MiB/s, done.
Resolving deltas: 100% (43/43), done.
* (HEAD detached at FETCH_HEAD)
  master
=> Compressing and cleaning up git repository

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

安裝後重新啟動終端機,輸入nvm -v顯示版本資訊即代表安裝成功。

% nvm -v
0.39.1


安裝指定Node.js版本

輸入nvm install <node_version>安裝指定的Node.js版本。

例如輸入nvm install 16.20.2安裝16.20.2版本如下。

% nvm install 16.20.2
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 shasum -a 256
Checksums matched!
Now using node v16.20.2 (npm v8.19.4)

輸入node -v顯示目前的Node.js版本。

% node -v
v16.20.2

輸入nvm ls列出已安裝的版本。

% nvm ls
->     v16.20.2
       v18.12.0
         system
default -> 18.12.0 (-> v18.12.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.12.0) (default)
stable -> 18.12 (-> v18.12.0) (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2
lts/hydrogen -> v18.19.1 (-> N/A)
lts/iron -> v20.11.1 (-> N/A)


切換Node.js版本

輸入nvm use <node_version>切換到指定版本。

% nvm use 16.20.2
Now using node v16.20.2 (npm v8.19.4)


沒有留言:

AdSense