【问题标题】:Homebrew issues installing Node & NPMHomebrew 安装 Node 和 NPM 时出现问题
【发布时间】:2020-01-24 13:50:53
【问题描述】:

操作系统 - macOS Catalina - 版本 10.15.2

我在 Mac 和我的 Windows 10 机器上使用了 bash shell,并在许多安装中使用了 apt-get。最近(可能在更新后)我注意到当我在 bash 中时,我无法再运行 apt-get。

[bash-3.2$ apt-get
bash: apt-get: command not found

这很奇怪,因为我在这台机器上多次使用 apt-get through bash。尝试熟悉 zsh shell,我已经成功安装了 homebrew。

% brew -v
Homebrew 2.2.4
Homebrew/homebrew-core (git revision 57b7f; last commit 2020-01-24)

看起来不错。现在是时候加载 Node(它总是在旁边安装 npm)

% brew install node
Warning: node 13.7.0 is already installed, it's just not linked
You can use 'brew link node' to link this version.

% brew link node
Linking /usr/local/Cellar/node/13.7.0... 
Error: Could not symlink include/node/common.gypi

好的...

% brew link --overwrite node
Linking /usr/local/Cellar/node/13.7.0... 
Error: Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.

这就是我尝试从 zsh 运行节点时剩下的内容

% node -v
zsh: command not found: node
% npm -v
env: node: No such file or directory

如果我尝试在 sudo 中运行 brew,它会阻止 root 访问,理解。如果我尝试从节点的网站安装节点,我会收到此错误

“node-v12.14.1.pkg”无法打开,因为Apple无法检查它是否存在恶意软件。

有没有在 zsh 和 homebrew 方面有更多经验的人知道如何让我进入 zsh 中的节点?

我真的很喜欢使用像:npm create-react-app 这样的包。

来自 brew doctor 的更新

来自酿酒医生:

Warning: Unbrewed header files were found in /usr/local/include. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. 列出大约 150 个文件,然后

Warning: You have unlinked kegs in your Cellar. Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run 'brew link' on these: node

Warning: Broken symlinks were found. Remove them with 'brew cleanup': 我运行了 brew cleanup 但出现错误 Error: Permission denied @ apply2files - /usr/local/lib/node_modules/npm/node_modules/.bin/JSONStream

【问题讨论】:

  • brew doctor 说什么?
  • 来自 brew doctor:Warning: Unbrewed header files were found in /usr/local/include. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted. 列出了大约 150 个文件,然后在这些文件上添加了 Warning: You have unlinked kegs in your Cellar. Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run brew link`:node` Warning: Broken symlinks were found. Remove them with brew cleanup: 我运行了 brew cleanup
  • 鉴于MacOS没有 apt-get,你之前是怎么安装的? (并且可能:为什么你之前安装过它?MacOS 不是 debian 风格,homebrew 是一般推荐的包管理器)你试过重新运行那个安装吗?至于安装 Node,这是您不想使用 brew 的情况之一,但 nvm 在管理您的节点安装方面做得更好。
  • 当然,只是想知道您为什么需要它。另外,如果你错过了,你真的想要 nvm 用于 Node,而不是 brew install node
  • 嘿,这是 brew 实际上与有用相反的一个用例,尽管对于几乎所有其他事情来说它都非常方便。你如何运行你显示的 bash 找不到 apt-get 了?只是标准应用程序 -> 实用程序 -> 终端?

标签: node.js homebrew zsh


【解决方案1】:

我正在处理 React 项目并面临同样的问题。我以这种方式解决了不删除自制软件只是删除当前节点并重新安装。


brew install node


它正在与这些孩子一起工作;)

node -v

npm -v

【讨论】:

    【解决方案2】:

    警告:如果您在 /usr/local 中有任何重要内容,或者如果您在自制软件中有不想丢失的配置,则此解决方案可能很危险。如果您只是使用 ZSH 并且主要使用 homebrew 作为包管理器,那么这可能是一个安全的选择。

    感谢大家的帮助。这里发生了很多事情,所以对于任何有类似问题的人来说。

    • 卸载自制软件uninstall homebrew
    • 擦除 /usr/local 的全部内容
    • 使用 ruby​​ 安装自制软件

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    • 安装 wget brew install wget
    • 安装节点brew install node
    • 检查 brew 安装 brew doctor

    Your system is ready to brew.

    • 检查节点node -v

    v13.7.0

    • 检查 npm npm -v

    6.13.6

    • 进入节点node
    • 从此过上幸福的生活

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-29
      • 2014-09-22
      • 2013-01-07
      • 1970-01-01
      • 2019-01-13
      • 2012-09-03
      • 2018-12-05
      • 2012-09-02
      相关资源
      最近更新 更多