• 欢迎访问少将全栈,学会感恩,乐于付出,珍惜缘份,成就彼此、推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 吐槽,投稿,删稿,交个朋友,商务沟通欢迎加博主微信:amlhbmdfc2hhb2Jv (Base64) 接头暗号:少将
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏少将全栈吧
  • 欢迎加博主微信:amlhbmdfc2hhb2Jv (Base64) 接头暗号:少将

Macos安装brew环境,用brew安装nvm,用nvm安装node

Java admin 2个月前 (09-17) 266次浏览 已收录 0个评论 扫描二维码

需要重新折腾一波环境,brew少不了

一.安装brew

brew官网:

https://brew.sh/index_zh-cn

没有梯子的话,可能需要换源,安装zsh的时候就提示ssl有问题

安装脚本:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装完成后:

Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the ‘Next steps’ section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations

==> Next steps:
– Run these two commands in your terminal to add Homebrew to your PATH:
echo ‘eval “$(/opt/homebrew/bin/brew shellenv)”‘ >> /Users/abel/.zprofile
eval “$(/opt/homebrew/bin/brew shellenv)”
– Run brew help to get started
– Further documentation:
https://docs.brew.sh

验证一下:

brew -v
Homebrew 3.6.1
Homebrew/homebrew-core (git revision a610f378f50; last commit 2022-09-17)

 

二.安装nvm环境

brew install nvm
==> Downloading https://ghcr.io/v2/homebrew/core/nvm/manifests/0.39.1_1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/nvm/blobs/sha256:6e14c8a2bf9421
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Pouring nvm–0.39.1_1.all.bottle.tar.gz
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

You should create NVM’s working directory if it doesn’t exist:

mkdir ~/.nvm

Add the following to ~/.zshrc or your desired shell
configuration file:

export NVM_DIR=”$HOME/.nvm”
[ -s “/opt/homebrew/opt/nvm/nvm.sh” ] && . “/opt/homebrew/opt/nvm/nvm.sh” #
export M2_HOME=/usr/local/apache-maven-3.8.6
This loads nvm
[ -s “/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm” ] && . “/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm” # This loads nvm bash_completion

You can set $NVM_DIR to any location, but leaving it unchanged from
/opt/homebrew/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.

Type nvm help for further information.
==> Summary
🍺 /opt/homebrew/Cellar/nvm/0.39.1_1: 9 files, 184.1KB
==> Running brew cleanup nvm
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew).

安装完后配置环境变量

其次需要在shell的配置文件(~/.bashrc, ~/.profile, or ~/.zshrc)中添加如下内容:

# For NVM
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

注意配置的顺序,以防开启新终端,node出现找不到的情况。

重启终端,命令行下即可使用nvm,使用nvm install <version>进行对应的node版本安装,

node官网:https://nodejs.org/en/

使用nvm install 16.17.0,安装的版本是v16.17.0。

使用nvm use <version>使用,

再通过nvm alias default <version>确保有默认版本。最后使用nvm ls查看。

nvm install 16.17.0
Downloading and installing node v16.17.0…
Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-darwin-arm64.tar.xz&#8230;
######################################################################### 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v16.17.0 (npm v8.15.0)
Creating default alias: default -> 16.17.0 (-> v16.17.0)

验证node版本

node -v
v16.17.0

npm -v
8.15.0

 

brew方式补充

如果之前通过’brew install node’方式安装过node,那么需要先删除系统中存在的node:

brew remove --force node
sudo rm -r /usr/local/lib/node_modules

brew prune
sudo rm -r /usr/local/include/node

# 检查brew是否正常
brew doctor

验证nvm版本:

nvm -v
0.39.1

 

喜欢 (0)
[🍬谢谢你请我吃糖果🍬🍬~]
分享 (0)
关于作者:
少将,关注Web全栈开发、项目管理,持续不断的学习、努力成为一个更棒的开发,做最好的自己,让世界因你不同。
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址