为什么在 Windows 上不能识别节点版本管理器(NVM) ?

我正在尝试降级我的节点版本

我跑过去:

npm install nvm

然后将 bin 文件夹导出到 Windows 路径变量,

C:\Program Files (x86)\nodejs\node_modules\npm\bin

但我还是得到:

“ nvm”不能识别为内部或外部命令。

我是否应该向 path 变量添加另一个路径?

405887 次浏览

First off, I use nvm on linux machine.

When looking at the documentation for nvm at https://www.npmjs.org/package/nvm, it recommendations that you install nvm globally using the -g switch.

npm install -g nvm

Also there is a . in the path variable that they recommend.

export PATH=./node_modules/.bin:$PATH

so maybe your path should be

C:\Program Files (x86)\nodejs\node_modules\npm\\.bin

nvm was designed for Linux. nvmw, which is completely different, broke around node v0.10.30. Try NVM for Windows.

NVM Installation & usage on Windows

Below are the steps for NVM Installation on Windows:

NVM stands for node version manager, which will help to switch between node versions while also allowing to work with multiple npm versions.

  • Install nvm setup.
  • Use command nvm list to check list of installed node versions.
  • Example: Type nvm use 6.9.3 to switch versions.

For more info

I created a universal nvm that works on both Unix (bash) and Windows, base on another simple nvm.

It doesn't need admin on Windows, but requires PowerShell 4+ and the right to execute scripts.

https://www.npmjs.com/package/@jchip/nvm#installation

The first thing that we need to do is install NVM.

  1. Uninstall existing version of node since we won’t be using it anymore
  2. Delete any existing nodejs installation directories. e.g. “C:\Program Files\nodejs”) that might remain. NVM’s generated symlink will not overwrite an existing (even empty) installation directory.
  3. Delete the npm install directory at C:\Users[Your User]\AppData\Roaming\npm We are now ready to install nvm. Download the installer from https://github.com/coreybutler/nvm/releases

To upgrade, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations. Make sure you use the same installation and symlink folder. If you originally installed to the default locations, you just need to click “next” on each window until it finishes.

Credits Directly copied from : https://digitaldrummerj.me/windows-running-multiple-versions-of-node/

1.downlad nvm
2.install chocolatey
3.change C:\Program Files\node   to C:\Program Files\nodejsx

emphasized textThe first thing that we need to do is install NVM. website : https://learn.microsoft.com/en-us/windows/nodejs/setup-on-windows

NVM can be used to manage various node version :

  • Step1: Download NVM for Windows

  • Step2: Choose nvm-setup.zip

  • Step3: Unzip & click on installer.

  • Step4: Check if nvm properly installed, In new command prompt type nvm

  • Step5: Install node js using nvm : nvm install <version> : The version can be a node.js version or "latest" for the latest stable version

  • Step6: check node version - node -v

  • Step7(Optional)If you want to install another version of node js - Use STEP 5 with different version.

  • Step8: Check list node js version - nvm list

  • Step9: If you want to use specific node version do - nvm use <version>

As an node manager alternative you can use Volta from LinkedIn.

An alternative to nvm-windows, which is mentioned in other answers would be Nodist.

I've had some issues with nvm-windows and admin privileges, which Nodist doesn't seem to have.

I know I'm late here but this may help in the future if someone looking for NVM to install in Windows or linux
run this command in cmd

       $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

I will list two ways. You can choose one Whichever works for you.

1. Using installer

Download nvm-setup.zip and unzip the file and install it, keeping the configurations default.

1. Use curl Copy the below command and run it in your terminal

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

After this reopen/open terminal and check the nvm version runing below command.

nvm -v

And that's it.

So this answer is for windows users that are using git bash or some other console emulator like cmder ... if you're using CMD this solution will not work for you also why? why are you still using CMD?

I know this is a pretty old post but I just achieved this yesterday and wanted to add my answer for anyone looking to do the same.

  • First check if you have .bashrc profile in your home directory by typing ls -alh ~ (by default this doesn't exist)
  • if it doesn't exist type this command to generate a .bashrc profile with default values in it cat /etc/bash.bashrc > ~/.bashrc (if it does exist skip this step)
  • Download and run the nvm install script as provided in the nvm docs page curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash (make sure you do this in your home directory)
  • then edit the new generated .bashrc profile file you created above; use nano/vim to do that nano ~/.bashrc and add the following to the bottom of the file export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm and save your .bashrc file with the changes.
  • lastly source your .bashrc file by typing source ~/.bashrc
  • verify installation nvm --version

and now you have nvm installed and you can use the commands as per https://github.com/nvm-sh/nvm#usage

If someone is looking for install on Window 11! Not directly relevant here, but might be useful.

It is immaterial if you install NVM (version 1.1.9.) say after the node (16.15.1) is already installed. During the nvm installation process, it asks for the right to manage the existing node version and symlinks that.

Get the version from the GitHub repo, I opted for the zip version.

https://github.com/coreybutler/nvm-windows/releases

Double click the application and it is just a few steps.