Sivo 悉见

Mac 安装Homebrew&nvm

我 · 更新于 2025/10/30

安装homebrew

终端输入命令


 
  1.  
    <div class="hljs-ln-code" style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; padding: 0px; font-synthesis-style: auto; overflow-wrap: break-word; font-size: 14px; float: left; height: 22px;">
    <div class="hljs-ln-line" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-synthesis-style: auto; overflow-wrap: break-word;"><code class="language-bash hljs" style="box-sizing: border-box; outline: 0px; display: block; overflow-x: auto; padding: 8px; color: rgb(171, 178, 191); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-radius: 4px; line-height: 22px; text-wrap-mode: nowrap; overflow-wrap: break-word; tab-size: 4; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-synthesis-style: auto;">/bin/zsh -c <span class="hljs-string" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: rgb(152, 195, 121); font-synthesis-style: auto; overflow-wrap: break-word;">&quot;<span class="hljs-subst" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: rgb(224, 108, 117); font-synthesis-style: auto; overflow-wrap: break-word;"><span class="hljs-subst" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-synthesis-style: auto; overflow-wrap: break-word;">$(curl -fsSL</span></span></span></code></div>
    </div>
    </li>
    <li style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; list-style: none; font-synthesis-style: auto; overflow-wrap: break-word; height: 22px;">
    <div class="hljs-ln-numbers" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-synthesis-style: auto; overflow-wrap: break-word; font-size: 14px; float: left; height: 22px; width: 24px; border-right: 1px solid rgb(197, 197, 197);">
    <div class="hljs-ln-line hljs-ln-n" data-line-number="2" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px 8px 0px 0px; text-align: right; font-synthesis-style: auto; overflow-wrap: normal;">&nbsp;</div>
    </div>
    
    <div class="hljs-ln-code" style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; padding: 0px; font-synthesis-style: auto; overflow-wrap: break-word; font-size: 14px; float: left; height: 22px;">
    <div class="hljs-ln-line" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; font-synthesis-style: auto; overflow-wrap: break-word;"><code class="language-bash hljs" style="box-sizing: border-box; outline: 0px; display: block; overflow-x: auto; padding: 8px; color: rgb(171, 178, 191); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-radius: 4px; line-height: 22px; text-wrap-mode: nowrap; overflow-wrap: break-word; tab-size: 4; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-synthesis-style: auto;"><span class="hljs-subst" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: rgb(224, 108, 117); font-synthesis-style: auto; overflow-wrap: break-word;">https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)</span>&quot;</code></div>
    </div>
    </li>
    

安装nvm

brew install nvm

打开zshrc

vi ~/.zshrc

输入命令

# 对于 zsh (推荐,因为 macOS 新版本默认使用 zsh)
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"' >> ~/.zshrc

# 重新加载配置
source ~/.zshrc

  1.  

刷新zsh

source .zshrc

安装nvm

nvm install xxxx(版本号)

报错:zsh: bad CPU type in executable: node

解决:终端输入

/usr/sbin/softwareupdate --install-rosetta --agree-to-license