如何在 Mac 上安装 NVM

发布于 2025-01-20 22:49:31 字数 791 浏览 3 评论 0原文

我尝试使用以下命令在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

帅的被狗咬 2025-01-27 22:49:31

有一个使用“Rosetta 2”的解决方案
从终端:

$ sudo softwareupdate --install-rosetta

使用curl安装NVM(在NVM自述文件中找到)

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

然后安装任何节点版本(示例安装最新)

$ nvm install node

检查节点版本

$ node -v

源:https://dev.to/httpjunkie/setup-node-version-manager-nvm-on-mac-m1-7kl

There is a solution using 'Rosetta 2'
From terminal:

$ sudo softwareupdate --install-rosetta

Install NVM using curl (found on the NVM Readme)

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

Then install whatever Node version (example installs latest)

$ nvm install node

Check Node Version

$ node -v

Source: https://dev.to/httpjunkie/setup-node-version-manager-nvm-on-mac-m1-7kl

南七夏 2025-01-27 22:49:31

Homebrew(brew)使安装和管理nvm的版本变得容易。
如果您已经有可用的自制,请运行brew install nvm。您将全部设定。

Homebrew (brew) makes it easy to install and manage versions of nvm.
If you have homebrew already available, please run brew install nvm. And you will be all set.

情绪少女 2025-01-27 22:49:31

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 file
with 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 run source ~/.zprofile in case of bash, you can then use NVM.

药祭#氼 2025-01-27 22:49:31

我花了半天时间试图弄清楚为什么 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!

辞取 2025-01-27 22:49:31

我发现在任何问题上配置nvm的最简单方法是以下...

删除上一个配置(如果有)...

brew uninstall --ignore-dependencies node
brew uninstall --force node

安装nvm

brew install nvm

创建nvm < /code>目录目录的目录...

mkdir ~/.nvm

〜/.zshrc shell中设置路径

export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # 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

现在您可以确认nvm

nvm --version

现在开始安装最新的稳定<代码> node 带有nvm

nvm -lts

verify node版本

node -v

使用nvm naster&lt; node安装不同的节点版本-version&gt; IE NVM安装14。列出所有已安装的节点版本nvm ls,并使用nvm使用&lt; node-version&gt; ie NVM使用21

The simplest way I found to configure the nvm with any issue is the following...

remove the previous configs if any...

brew uninstall --ignore-dependencies node
brew uninstall --force node

install nvm

brew install nvm

Create an nvm directory at the root of the directory...

mkdir ~/.nvm

set the path in ~/.zshrc shell

export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # 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

now you can confirm nvm version by

nvm --version

Now start installing the latest stable node with nvm

nvm -lts

verify node version

node -v

install a different node version with nvm install <node-version> ie nvm install 14. list all installed node versions nvm ls and use particular version with nvm use <node-version> ie nvm use 21

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文