網頁

2022/12/9

Mac Homebrew安裝Node.js 2022

Mac使用Homebrew安裝Node.js


範例環境:

  • macOS Ventura 13.0.1
  • Homebrew 3.6.14


安裝Node.js

在終端機(terminal)命令列輸入brew install node開始安裝。

% brew install node
...
==> Installing dependencies for node: brotli, c-ares, libnghttp2 and libuv
==> Installing node dependency: brotli
==> Pouring brotli--1.0.9.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/brotli/1.0.9: 25 files, 2.3MB
==> Installing node dependency: c-ares
==> Pouring c-ares--1.18.1_1.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/c-ares/1.18.1_1: 87 files, 645.7KB
==> Installing node dependency: libnghttp2
==> Pouring libnghttp2--1.51.0.ventura.bottle.1.tar.gz
🍺  /usr/local/Cellar/libnghttp2/1.51.0: 13 files, 721.9KB
==> Installing node dependency: libuv
==> Pouring libuv--1.44.2.ventura.bottle.1.tar.gz
🍺  /usr/local/Cellar/libuv/1.44.2: 51 files, 3.5MB
==> Installing node
==> Pouring node--19.2.0.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/node/19.2.0: 1,963 files, 52.5MB
==> Running `brew cleanup node`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

輸入node -v檢視安裝的版本目前為v19.2.0。

% node -v
v19.2.0

安裝Node.js會順帶安裝npm

輸入npm -v檢視安裝的版本目前為8.19.3。

% npm -v
8.19.3


測試

在終端機命令列輸入node進入Node.js執行環境,然後輸入console.log('hello world')結果如下。

% node
Welcome to Node.js v19.2.0.
Type ".help" for more information.
> console.log('hello world')
hello world
undefined

沒有留言:

張貼留言