如何安装 LTS 版本的 nodejs 通过自制

当我运行 brew install node它安装 v6.7.0 Current,但我想 LTS版本是在这个时候写 v4.6.0 LTS。我需要发出哪些命令来安装 LTS版本的节点通过家酿。

68746 次浏览

You can use brew install node@4, brew install node@6, or brew install node@8 command to install LTS version of Node via Homebrew.

If another version of Node is already installed, you should uninstall it first to avoid conflicts.

Also note that LTS versions of node (e.g. node@10) are keg-only and must either be linked with --force (brew link --force node@10) or you need to add the binary to your path by running:

echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> ~/.bashrc

You can always look up LTS and stable versions from node releases page and also look at homebrew formulae here.
It shows how u can install stable version vs other versions. For example right now, brew install node@10 will install LTS version 10.16.

You can also use nvm (Node version manager) to install multiple node versions (LTS, Current, etc.) and use them as per project dependencies.

Install nvm:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Install Node LTS node version:

nvm install --lts

Install node v14: (mention node version to install that specific version)

nvm install 14

Install current Node version

nvm install node

Now, that you've installed bunch of Node versions. You can set anyone to be default.
Set LTS as your default node version:

nvm use --lts