You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

能否在Windows/Mac系统通过命令行或不使用Node安装程序安装Node?

Answers to Your Node.js Installation Questions

Hey there! Let's tackle your two Node.js installation questions one by one—super common asks, so I’ve got you covered.

1. Can I install Node.js via command line on Windows and Mac?

Absolutely! Both operating systems have easy command-line options, mostly using package managers or version managers. Here's how to do it:

Mac

  • Using Homebrew (the go-to package manager for Mac):
    If you don’t have Homebrew installed yet, run the official install script in your terminal (you can grab this from the Homebrew site):
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    Once Homebrew is set up, install Node.js with:
    brew install node
    
  • Using nvm (Node Version Manager) (perfect if you need to switch between multiple Node versions):
    Install nvm first by running its official install script (available on the nvm GitHub repo):
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
    
    Restart your terminal to apply changes, then install the latest Node.js version:
    nvm install node
    

Windows

  • Using Chocolatey (Windows' popular package manager):
    First, open Command Prompt or PowerShell as Administrator. Install Chocolatey with this script (from their official site):
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    
    Then install Node.js:
    choco install nodejs
    
  • Using nvm-windows:
    Grab the official nvm-windows installer (from its GitHub page), run it, then open a new terminal and install the latest Node version:
    nvm install latest
    

2. Can I install Node.js without using the official Node installer?

Yes, for sure! The command-line methods above already skip the official graphical installer, but there are also manual binary installation options if you want full control:

Mac

  • Manual binary setup:
    1. Head to the Node.js official site and download the macOS .tar.gz binary matching your system architecture.
    2. Open terminal, navigate to your download folder, and extract the file:
      tar -xzf node-vX.X.X-darwin-x64.tar.gz
      
      (Replace X.X.X with the actual version number you downloaded.)
    3. Move the extracted folder to a system directory like /usr/local (you’ll need admin rights):
      sudo mv node-vX.X.X-darwin-x64 /usr/local/node
      
    4. Add the Node bin directory to your system PATH by editing your shell config file (like ~/.zshrc or ~/.bashrc):
      export PATH="/usr/local/node/bin:$PATH"
      
    5. Restart your terminal and verify the installation with node -v.

Windows

  • Manual zip setup:
    1. Download the Windows .zip binary from the Node.js official site.
    2. Extract the zip file to a permanent folder, like C:\nodejs.
    3. Open System Properties > Advanced > Environment Variables.
    4. Under "System Variables", find and edit the Path variable, then add C:\nodejs\bin to the list.
    5. Open a new Command Prompt or PowerShell window, then check if Node is installed with node -v.

Version managers like nvm (Mac) or nvm-windows are also a fantastic alternative here—they handle version switching automatically and avoid messing with system-wide file paths directly.

内容的提问来源于stack exchange,提问作者rahil sharma

火山引擎 最新活动