如何在 Mac 上安装 NVM
我尝试使用以下命令在 Mac 上安装 NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
但是,我收到一条错误消息:“语法错误接近意外的 `(”。更多详细信息下面提供了错误日志,我做错了什么
VFZ:repo2022 john$ 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 4934 100 4934 0 0 686 0 0:00:07 0:00:07 --:--:-- 686
bash: line 1: syntax error near unexpected token `('
bash: line 1: `<!-- Copyright (C) 2016 Intel Corporation. All rights reserved. -->'
VFZ:repo2022 john$
?
I am trying to install NVM on my Mac using the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
However, I am getting an error with the message: "syntax error near unexpected `(". More details on the error log are provided down below. What am I doing wrong?
VFZ:repo2022 john$ 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 4934 100 4934 0 0 686 0 0:00:07 0:00:07 --:--:-- 686
bash: line 1: syntax error near unexpected token `('
bash: line 1: `<!-- Copyright (C) 2016 Intel Corporation. All rights reserved. -->'
VFZ:repo2022 john$
System - MAC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一个使用“Rosetta 2”的解决方案
从终端:
使用curl安装NVM(在NVM自述文件中找到)
然后安装任何节点版本(示例安装最新)
检查节点版本
源:https://dev.to/httpjunkie/setup-node-version-manager-nvm-on-mac-m1-7kl
There is a solution using 'Rosetta 2'
From terminal:
Install NVM using curl (found on the NVM Readme)
Then install whatever Node version (example installs latest)
Check Node Version
Source: https://dev.to/httpjunkie/setup-node-version-manager-nvm-on-mac-m1-7kl
Homebrew(
brew
)使安装和管理nvm
的版本变得容易。如果您已经有可用的自制,请运行
brew install nvm
。您将全部设定。Homebrew (
brew
) makes it easy to install and manage versions ofnvm
.If you have homebrew already available, please run
brew install nvm
. And you will be all set.continue
If curl doesn't work you can use wget, for which you should have wget installed which you can install using homebrew.
brew install wget
Then run the following command,
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
.The installer will automatically update the profiles files but if it doesn't you can update it manually like this.
First identify which shell is it that you are using:
echo $0
if its zsh, update the
~/.zprofile
file.if its bash, update the
~/.bash_profile
filewith the following lines
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
After that you can run
source ~/.bashrc
in case of bash, or runsource ~/.zprofile
in case of bash, you can then use NVM.我花了半天时间试图弄清楚为什么 NVM 不起作用,直到我看到这篇文章 https://github.com/nvm-sh/nvm/issues/987。
几乎每个人(包括我自己)在 bash 配置文件中都有一个“do”的自定义别名。
就我而言,我必须删除这一行:
alias do='cd ~/Downloads && open "$(ls -t ~/Downloads | head -1)"'
do
是一个保留关键字,因此使用别名将导致任何使用它的 bash 脚本失败(或执行不同)还要检查您的别名中的其他保留关键字,例如
done
希望这将为您节省数小时的挫败感!
I spend half a day trying to figure out why NVM wasnt working, until i came across this post https://github.com/nvm-sh/nvm/issues/987.
Almost everyone (including myself) had a custom alias for 'do' in the bash profile.
In my case i had to remove this line:
alias do='cd ~/Downloads && open "$(ls -t ~/Downloads | head -1)"'
do
is a reserved keyword, so aliasing it will cause any bash script that uses it to fail (or act differently)Also check for other reserved keywords in your alias' such as
done
Hope this will save you hours of frustration!
我发现在任何问题上配置
nvm
的最简单方法是以下...删除上一个配置(如果有)...
安装
nvm
创建
nvm < /code>目录目录的目录...
在
〜/.zshrc
shell中设置路径现在您可以确认
nvm
现在开始安装最新的稳定<代码> node 带有
nvm
verify
node
版本node -v
使用
nvm naster&lt; node安装不同的节点版本-version&gt;
IENVM安装14
。列出所有已安装的节点版本nvm ls
,并使用nvm使用&lt; node-version&gt;
ieNVM使用21
The simplest way I found to configure the
nvm
with any issue is the following...remove the previous configs if any...
install
nvm
Create an
nvm
directory at the root of the directory...set the path in
~/.zshrc
shellnow you can confirm
nvm
version byNow start installing the latest stable
node
withnvm
verify
node
versionnode -v
install a different node version with
nvm install <node-version>
ienvm install 14
. list all installed node versionsnvm ls
and use particular version withnvm use <node-version>
ienvm use 21