V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Livid
V2EX  ›  Node.js

brew 里的 node.js 安装的时候不创建 npm 的符号链接?

  •  
  •   Livid · 2014-05-07 16:51:09 +08:00 · 11354 次点击
    这是一个创建于 3640 天前的主题,其中的信息可能已经有所发展或是发生改变。
    brew link node 然后执行 npm 还是 command not found?
    21 条回复    2020-01-05 11:19:53 +08:00
    wtl
        1
    wtl  
       2014-05-07 17:02:38 +08:00
    也碰到这个问题 后来就直接下安装包了
    dorentus
        2
    dorentus  
       2014-05-07 17:07:21 +08:00
    我的是有的

    莫非你是带 --without-npm 参数安装的?
    Livid
        3
    Livid  
    MOD
    OP
       2014-05-07 17:07:48 +08:00
    @dorentus 就用 brew install node 装的。

    刚刚也直接去下载官网安装包了。
    zieglar
        4
    zieglar  
       2014-05-07 17:08:13 +08:00
    还是用 nvm 来处理比较好
    fundon
        5
    fundon  
       2014-05-07 17:08:36 +08:00   ❤️ 2
    `brew edit node` 默认加了 `--without-npm`

    执行 `brew install node --with-npm`
    fundon
        6
    fundon  
       2014-05-07 17:09:17 +08:00
    推荐nvm,切换版本方便
    ohsc
        7
    ohsc  
       2014-05-07 17:10:55 +08:00
    单独安装吧,npm本身可以自我升级,再纳入brew管理会有问题。

    https://github.com/Homebrew/homebrew/pull/27479
    dorentus
        8
    dorentus  
       2014-05-07 17:13:05 +08:00
    @fundon 难怪。。他们为啥要这么做。。

    不过更奇怪的是我直接装还是带 npm 的:

    Livid
        9
    Livid  
    MOD
    OP
       2014-05-07 17:13:54 +08:00
    @dorentus 你的 brew 已经有一段时间没更新了。
    ohsc
        10
    ohsc  
       2014-05-07 17:17:47 +08:00
    如果你已经安装了npm,更新node后brew会执行 /usr/local/bin/npm update npm -g
    dorentus
        11
    dorentus  
       2014-05-07 17:23:42 +08:00
    @Livid 嗯,确实是这个原因。

    不过其实就是晚了一天没更新。

    原因是这个 commit: https://github.com/Homebrew/homebrew/commit/15846a5d131f69ec8e9ddc263f1cabfa63b0c2f4#diff-ba7ac8bf3cbc78ff35d6909b6074ee5e

    我觉得大概是这样:
    虽然 formula 里面很早就默认加了 --without-npm,但是平常大家不带参数装的时候,其实是直接下载的预先打包好的 tarball(bottled do ... end 那里),然后这个 commit 之前的 0.10.26 版的 tarball,估计还是带了 bin/npm 的,但是 0.10.28 里面它被删掉了……
    chrisyipw
        12
    chrisyipw  
       2014-05-07 17:28:48 +08:00
    似乎和版本有关的,brew install node 一直都会安装 npm,但安装 dev 时则不会安装。

    鉴于 brew 安装的 npm 之前有过不少问题,比如 npm update -g 无法更新 npm 自身 (报错) ,可能独立安装 npm 会更保险。

    至于 nvm,这家伙目前并没有设置全局的功能,我是 brew 安装一个稳定版作为全局使用,用 nvm 控制不同版本的切换。
    fundon
        13
    fundon  
       2014-05-07 17:36:23 +08:00   ❤️ 1
    还有另外一个选择,使用boxen管理环境,装https://github.com/boxen/puppet-nodejs

    默认带了 nodenv 命令,比nvm方便

    ```
    λ ~ nodenv help (node-v0.10.26) 17:32:59
    Usage: nodenv <command> [<args>]

    Some useful nodenv commands are:
    exec Execute a command from a particular NodeJS version.
    shell Set NODENV_VERSION for the lifetime of a shell.
    local Persist the preferred NodeJS version in the cwd.
    global Persist the preferred NodeJS default version.
    install Install a version of NodeJS.
    uninstall Uninstall a version of NodeJS.
    version Show the current NodeJS version.
    versions Display all versions of NodeJS installed in `${NODENV_ROOT}/versions/*'.
    rehash Rehash nodenv shims (run this after installing executables)

    See `nodenv help <command>' for information on a specific command.
    ```
    mahone3297
        14
    mahone3297  
       2014-05-07 20:00:53 +08:00
    port安装。。。
    sd4399340
        15
    sd4399340  
       2014-05-07 22:10:55 +08:00
    试试 brew postinstall node

    我刚才更新node的时候brew报这个错

    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR! /Users/pinky/npm-debug.log
    npm ERR! not ok code 0
    Warning: The post-install step did not complete successfully
    You can try again using `brew postinstall node`

    不过我也没注意运行这个之前npm正常不,反正运行后是正常的
    newtonisaac
        16
    newtonisaac  
       2014-05-09 01:25:02 +08:00 via iPad
    .npm目录及子目录权限改为可读可写
    sdhjl2000
        17
    sdhjl2000  
       2014-05-27 17:53:39 +08:00
    刚遇到这个问题,根据提示发现是权限问题:sudo brew postinstall node
    Feiox
        18
    Feiox  
       2014-08-07 10:47:16 +08:00
    @sd4399340 我遇到了同样的报错信息,是在 brew install node 时就遇到的。您是怎么解决的呢
    sd4399340
        19
    sd4399340  
       2014-08-09 17:03:30 +08:00
    @Feiox 我好像最后就是用 brew postinstall node
    cz5424
        20
    cz5424  
       2020-01-05 11:19:03 +08:00
    brew install node 发现没有 npm
    带有提示 brew postinstall node 失败
    brew postinstall node --debug
    看到 npm 目录报没有权限 => /usr/local/lib/node_modules/npm
    chown 授权
    brew postinstall node 成功
    cz5424
        21
    cz5424  
       2020-01-05 11:19:53 +08:00
    ps: 现在的 brew 不允许 sudo 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3222 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:32 · PVG 20:32 · LAX 05:32 · JFK 08:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.