dangyuluo
V2EX  ›  macOS

MacOS 如何干净地安装 NPM?

  •  
  •   dangyuluo · Apr 28, 2023 · 4237 views
    This topic created in 1285 days ago, the information mentioned may be changed or developed.

    对 NodeJS 不是很了解,但是有个工具需要通过 npm 安装。请问 MacOS 下有什么推荐的 npm 虚拟环境么?我不想每次启动 shell 都默认引入一大堆包。

    25 replies  •  2023-05-03 11:29:01 +08:00
    coyoteer
    coyoteer
    Apr 28, 2023
    1
    为什么直接装 npm“每次启动 shell 都默认引入一大堆包”?
    yuhangch
    yuhangch
    Apr 28, 2023
    2
    cat /usr/local/opt/node@16/bin/npm
    #!/usr/bin/env node
    require('../lib/cli.js')(process)
    Puteulanus
    Puteulanus
    Apr 28, 2023
    3
    https://nodejs.org/en/download 有 macOS Binary 下载
    crysislinux
    crysislinux
    Apr 28, 2023
    4
    对多版本没有需求就 brew 装好了。你说的引入一大堆包是指 nvm 之类的吧。没需求你就可以不用。
    uyZL3221XZ2xGZ3D
    uyZL3221XZ2xGZ3D
    Apr 28, 2023 via Android
    5
    曲线一点,把这些跑在 docker 里面
    beginor
    beginor
    Apr 28, 2023 via Android
    6
    @tanhui2333 Mac 上 docker 的磁盘 IO 不行, 尝试过这个,放弃了
    huijiewei
    huijiewei
    Apr 28, 2023
    7
    brew install node 就挺干净的啊。
    xlongye
    xlongye
    Apr 28, 2023
    9
    fnm 了解一下
    nino
    nino
    Apr 28, 2023
    10
    不用安装,直接用 npx 运行
    Leonard
    Leonard
    Apr 28, 2023
    11
    我是用 brew 的
    IvanLi127
    IvanLi127
    Apr 28, 2023 via Android
    12
    欸。。有这么脏吗🤣
    seanzxx
    seanzxx
    Apr 29, 2023
    13
    还是 docker 舒服
    good
    good
    Apr 29, 2023
    14
    @beginor Mac 上,我把 Docker 装到 Ubuntu 里效果还不错,要跑什么服务在本机上跑个 Nginx 反代一样就 Ok
    good
    good
    Apr 29, 2023
    15
    @beginor Ubuntu 虚拟机里
    cnhongwei
    cnhongwei
    Apr 29, 2023
    16
    使用 volta 安装管理 nodejs 的不同版本,这个和虚拟环境差不多。
    luckyc
    luckyc
    Apr 29, 2023
    17
    用 nvm 管理 nodejs 版本.
    nvm ls
    nvm install 16.19.1
    nvm use 16.19.1
    uyZL3221XZ2xGZ3D
    uyZL3221XZ2xGZ3D
    Apr 29, 2023
    18
    @beginor 所谓的磁盘 IO 不行会造成什么难以忍受的影响呢
    xtinput
    xtinput
    Apr 29, 2023
    19
    @good Docker Desktop 本身也是跑一台虚拟机,我是直接用系统的虚拟框架跑的 Debian ,Docker 跑 Debian 里面,macOS 上直接连接操作,没装虚拟机软件网卡只能 nat
    @beginor 直接找个 vmcli 调用系统的虚拟框架创建虚拟机,在虚拟机里跑 Docker 就行
    自荐: https://github.com/darvintang/dvtvmcli

    不要求版本就用 brew ,要求版本就 nvm ,然后自己配置好 prefix
    xtinput
    xtinput
    Apr 29, 2023
    20
    @tanhui2333 macOS 上的 Docker Desktop 很不好用,跑台虚拟机,在虚拟机里面跑 Docker 更好
    good
    good
    Apr 29, 2023
    21
    @xtinput 我是在 Parallels Desktop 里跑的 Ubuntu 虚拟机,比直接装在 Mac 效果好太多了,老的 Intel Mac 改虚拟机 风扇热度有很大改观.
    MrKrabs
    MrKrabs
    Apr 29, 2023
    22
    nvm 装到外置 ssd
    beginor
    beginor
    Apr 29, 2023 via Android
    23
    @good 在虚拟机里面的话映射磁盘文件什么的不方便
    beginor
    beginor
    Apr 29, 2023 via Android
    24
    @tanhui2333 就像你现在用机械盘那样
    deemoe
    deemoe
    May 3, 2023 via iPhone
    25
    我最近也遇到了这个问题,不过根据我的初步调查,好像 npm install 的包都是安装在工作目录下,并不会全局安装(除非 -g 指定)。

    不知道这个信息准不准确,如果有不准确的地方还请大佬拍砖🥲
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3015 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 80ms · UTC 12:07 · PVG 20:07 · LAX 04:07 · JFK 07:07
    ♥ Do have faith in what you're doing.