抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

macOS Big Sur 安装 Node.js

注意

切记不要在 Node.js 官网下载安装包直接安装,否则在安装 Hexo 时会出现 EACCES权限错误。

Hexo 官方文档中有如下说明:

For Mac / Linux 用户
如果在尝试安装 Hexo 的过程中出现 EACCES 权限错误,请遵循 由 npmjs 发布的指导 修复该问题。强烈建议 不要 使用 root、sudo 等方法覆盖权限

而在 由 npmjs 发布的指导 中有如下说明:

If you see an EACCES error when you try to install a package globally, you can either:
Reinstall npm with a node version manager (recommended),
or
Manually change npm’s default directory

如果在尝试全局安装软件包时看到EACCES错误,你可以
使用 node 版本管理器重新安装npm(推荐),
或者
手动更改npm的默认目录

Reinstall npm with a node version manager 部分的说明如下:

Reinstall npm with a node version manager
This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in “Downloading and installing Node.js and npm”. You do not need to remove your current version of npm or Node.js before installing a node version manager.

使用 node 版本管理器重新安装npm
这是避免权限问题的最好方法。要使用节点版本管理器重新安装npm,请按照“下载和安装Node.js和npm”中的步骤操作。在安装节点版本管理器之前,您不需要删除当前版本的npm或Node.js。

Downloading and installing Node.js and npm 部分的说明如下

We strongly recommend using a Node version manager like nvm to install Node.js and npm. We do not recommend using a Node installer, since the Node installation process installs npm in a directory with local permissions and can cause permissions errors when you run npm packages globally.

**我们强烈建议使用像nvm这样的Node版本管理器来安装Node.js和npm。**我们不建议使用Node安装程序,因为Node安装过程在具有本地权限的目录中安装npm,当您全局运行npm包时,可能会导致权限错误。

安装 Node Version Manager(nvm)

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

前往官网查看 Node.js 的最新版本
Node.js 官网

1
2
3
4
5
6
# 确认 nvm 是否安装成功
nvm

# 若提示 nvm: command not found
touch ~/.zshrc
# 由于 macOS 10.15 默认的 shell 是 zsh ,但 nvm 会寻找默认没有安装的 .zshrc 来更新,于是用touch ~/创建一个,创建完后重新再运行一次安装命令,安装完成后若还是提示 nvm: command not found ,就重新打开一个新的终端窗口。

安装 Node.js

1
2
3
4
5
6
7
8
9
10
# 前往官网查看 Node.js 的最新版本
# <version> 替换为对应版本号
nvm install v<version>
# nvm install v15.3.0

# 检查 Node.js 是否安装成功,若提示版本号则成功
node -v

# 检查 npm 是否安装成功,若提示版本号则成功
npm -v

评论