Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why doesnt work to switch node version via "nvm use" #321

Closed
4 of 13 tasks
lucya opened this issue Dec 11, 2017 · 49 comments
Closed
4 of 13 tasks

Why doesnt work to switch node version via "nvm use" #321

lucya opened this issue Dec 11, 2017 · 49 comments

Comments

@lucya
Copy link

lucya commented Dec 11, 2017

If this is a question about how to use NVM4W, please use stackoverflow instead.

If this is an issue regarding antivirus, make sure you search the existing issues first.

My Environment

  • Windows 7 or below (not truly supported due to EOL - see wiki for details)

I'm using NVM4W version:

  • 1.1.6

I have already...

  • read the README to be aware of npm gotchas & antivirus issues.
  • reviewed the wiki to make sure my issue hasn't already been resolved.
  • verified I'm using an account with administrative privileges.
  • searched the issues (open and closed) to make sure this isn't a duplicate.
  • made sure this isn't a question about how to use NVM for Windows, since gitter is used for questions and comments.

My issue is related to (check only those which apply):

  • settings.txt
  • proxy support (Have you tried version 1.1.0+?)
  • 32 or 64 bit support (Have you tried version 1.1.3+?)
  • Character escaping (Have you tried version 1.1.6+?)
  • A standard shell environment (terminal/powershell)
  • A non-standard shell environment (Cmder, Hyper, Cygwin, git)

Expected Behavior

i tried to switch v8.9.1 to 6.12.0 (node version)

Actual Behavior

but, it didnt switch to 6.12.0 or another versions.
(i installed 8.9.1 at last)

Steps to reproduce the problem:

i opened cmd via administrator.

C:\Windows\system32>nvm ls

  • 8.9.1 (Currently using 64-bit executable)
    7.1.0
    6.12.0

C:\Windows\system32>node -v
v8.9.1

C:\Windows\system32>nvm use 6.12.0
Now using node v6.12.0 (64-bit)

C:\Windows\system32>node -v
v8.9.1

C:\Windows\system32>nvm ls

  • 8.9.1 (Currently using 64-bit executable)
    7.1.0
    6.12.0
@dolphinfine
Copy link

the same

@cjy37
Copy link

cjy37 commented Dec 21, 2017

+1

@biologeek
Copy link

Same with nvm 1.1.5 :

C:\windows\system32>nvm version
1.1.5

C:\windows\system32>nvm ls

    8.9.2
  * 4.7.2 (Currently using 64-bit executable)

C:\windows\system32>nvm use 8.9.2
Now using node v8.9.2 (64-bit)

C:\windows\system32>node -v
v4.7.2

C:\windows\system32>

@di3orlive
Copy link

@biologeek same thing :/
did you find some solution ?

@coreybutler
Copy link
Owner

This occurs most often due to use of an unprivileged user account. Your account must have administrator-level permissions, because Windows requires it for symlinks. nvm use creates a symlink to the appropriate Node installation. If your symlink exists within C:\Program Files, you'll need elevated permissions (nvm4w will attempt to do this for you automatically).

@biologeek
Copy link

I am admin on my pc. Though I could overcome this issue by manually renaming folders so that nvm symlink points to the version I need.
Quick and dirty but no need to have admin access !

@coreybutler
Copy link
Owner

@biologeek - you still need admin access to rename directories within C:\Program Files because it is a protected directory on Windows (same is true for C:\windows\system32). Personally, I keep my NVM4W symlink in my user directory so this isn't an issue.

@edmael
Copy link

edmael commented Jan 25, 2018

+1 on this issue: I can't change the version.

@ituasdu
Copy link

ituasdu commented Apr 18, 2018

Workaround:
Renamed "C:\Program Files\nodejs" to "C:\Program Files\nodejsx",
Then from an elevated cmd called "nvm use 8.9.1" (any version you got should work..) and it started to work.
Problem seems to be if nodejs directory exists, nvm can not change it to a symlink and 'fails silently' would be nice with a fail and an error message stating the problem.

@razzeee
Copy link

razzeee commented May 2, 2018

Can confirm what @ituasdu said. Thanks!

@holiyo
Copy link

holiyo commented May 18, 2018

@ituasdu solved my problem,thx

@nan0
Copy link

nan0 commented May 22, 2018

Hi, same issue here.

NVM creates a a symlink to the installed node version.

The problem is that Windows 7 requires admin right levels to create a symlink, and it's not the case anymore in Windows 10.

A workaround is to use junctions ('hard' links) on Windows 7 with the parameter '/J'. Junctions don't require admin rights levels and a low privileges user accounts as mine can use it. Example:

nvm install 8.11.2
mklink /D /J node C:\PATH_TO_NVM\nvm\v8.11.2

Question: Wouldn't it be a good idea to use junctions instead of symlinks ? Or at least specify a option to nvm eg '--junctions' ?

I'm thinking about creating a pull request for this as it's blocking for my company. Would it be helpful ?

nan0 pushed a commit to nan0/nvm-windows that referenced this issue May 22, 2018
@ajbertra91
Copy link

@nan0 making a junction on windows 7 isn't working... it still won't switch versions.

C:\Program Files\nodejs contains v6.9.4 (installed before NVM4W installed).

C:\Users\[user]\AppData\Roaming\nvm contains v6.9.4\ and v8.11.3\

I ran the command you provided in your post:

Issue 1:
mklink /D /J node C:\Users\[user]\AppData\Roaming\nvm\v8.11.3 when I try to do it for v6.9.4 it says "Cannot create a file when that file already exists."

Issue 2:
Also, using nvm use v8.11.3 then nvm list it doesn't indicate that it actually is using either nvm installed node version.

Is there anything else that can be done?
How can I see the junctions that are created? Where do they actually exist?

I'm using:
Windows 7. no admin rights allowed for my user.

@ajbertra91
Copy link

never mind it does work. I realized that I was making the junction in the wrong folder.

renaming C:\Program Files\nodejs to C:\Program Files\ nodejsx
and then making the junction as "nodejs" and pointing it to C:\Users\[user]\AppData\Roaming\nvm\v8.11.3 worked!

So to sum up the solution is this:

with no stand alone node installed.

In the C:\Program Files\ folder use cmd to run mklink /D /J nodejs C:\Users\[user]\AppData\Roaming\nvm\v8.11.3

@coreybutler
Copy link
Owner

For those interested in contributing, thank you!

However; I want to point out that junctions were explicitly avoided because they will not work across different hard drives. This was a particular sore spot in enterprise networks with shared drives/mapped drives.

@mihirp1730
Copy link

@ituasdu It solved my problem,
Thanks for the solution.

@dangnuo7
Copy link

My computer is Windows 7, and I have administrator privileges. In the same situation, NVM cannot change version.My approach is to set up NVM_SYMLINK D:\Project\ NVM \ v8.11.4 in the environment variable.Switching node versions only requires changing the version number corresponding to the environment variable NVM path, such as: NVM_SYMLINK D:\Project\ NVM \ v6.9.0.In this way, although the problem was solved, every time I changed the version, it was troublesome, and I did not find a better solution for the moment.

@romanzrv
Copy link

The solution of "Sagan" from stack overflow works for me:
https://stackoverflow.com/questions/28313372/nvm-for-windows-not-working

@xianshenglu
Copy link

For me,

nvm list 

image

Then I remove v8.9.4 folder out of nvm.
image

After that:

nvm list 

image

Then, I move v8.9.4 back.

@ssisaias
Copy link

ssisaias commented Oct 31, 2018

This is happening for me on Windows 10 10.0.17134.165
I tried the solution mentioned by @ituasdu and it worked. thank you!!!

@JeanerK
Copy link

JeanerK commented Nov 23, 2018

If you found that after you try cmd like:
nvm use 6.10.0
and nodejs version has not been changed, you can start cmd.exe or powershell by administrator.
image

@jordanyim1
Copy link

I had the same problem when switching between node 6.6.0 and 7.9.0 (Windows 10) but ituasdu's solution wasn't working. Re-installing nvm didn't work either.

I ran nvm install latest (installed 11.3.0) and this somehow fixed it for me.

@xiaodeaux
Copy link

xiaodeaux commented Dec 19, 2018

Workaround:
Renamed "C:\Program Files\nodejs" to "C:\Program Files\nodejsx",
Then from an elevated cmd called "nvm use 8.9.1" (any version you got should work..) and it started to work.
Problem seems to be if nodejs directory exists, nvm can not change it to a symlink and 'fails silently' would be nice with a fail and an error message stating the problem.

This worked for me.
image

PS > nvm use 11.4.0
Now using node v11.4.0 (64-bit)
PS > node -v
v10.11.0
PS > nvm use 11.4.0
Now using node v11.4.0 (64-bit)
PS > node -v
v11.4.0

@patelpriyankaa
Copy link

@ituasdu worked for me too.. thanks.. :)

@piyushgaur01
Copy link

@ituasdu Thanks, worked like a charm. I believe this happens when people have NodeJS installed previously directly without nvm and then try to use node through nvm.

@PCASME
Copy link

PCASME commented Mar 1, 2019

This also works for me, thanks.

I don't know if this could drop some light to the issue but in my case I think this had happen after install a new version of node without nvm (manually). Seems that this action makes crazy nvm.

@monico-moreno
Copy link

monico-moreno commented Mar 21, 2019

@coreybutler any thoughts on installing the symlink on a folder that doesn't require admin privs? I know this might be slightly, bad form in Windows dev, but it will definitely side-step all of these issues, especially in a highly-locked-down, enterprise environment where getting admin privs is a huge pain.

Other pain is what I am currently suffering through (not because of nvmw) where, although I do indeed have admin privs in some instances, every time I want to switch between versions of node, I have to open up a whole other cmd window, run cmd as admin and finally run nvm use 10.15.1 (for example). then nav back to my dev, cmd window. argh. again, pain due to work env not because of nvmw. (nvmw is awesome btw).

just a thought. ;-)

@WendySanarwanto
Copy link

Run nvm use <node.js version you want to use> (e.g. nvm use 10.15.3) under Powershell ISE as Administrator resolved the issue in my Windows 10.

@lackovic
Copy link

lackovic commented Apr 24, 2019

I have to run nvm use any.version multiple times under Powershell As Administrator to get it to work. It randomly changes version at the first, second or third attempt (nvm version 1.1.7).

I tried to fix it by installing Link Shell Extension and doing the following steps:

  1. right click on C:\Program Files\nodejs
  2. select Pick Link Source
  3. right click on C:\Program Files
  4. select Drop as... > Symbolic Link
  5. rename nodejs - SymbolicLink to nodejsx

But unfortunately the problem is still occurring.

@mmahandev
Copy link

Can confirm @ituasdu solution worked for me also.

@edwinjoel1984
Copy link

@ituasdu works for me, thnks.

@coreybutler
Copy link
Owner

@monico-moreno - next time ping me via email when I don't respond for months at a time :) To answer your question, you can install to any folder you want using the installer. However; all symlinks on Windows require admin privileges, except for some developer modes on newer editions of Windows 10. Bottom line is admin privileges come into play at some point.

Also, maybe you can beta test the menu system when I wrap it up (switch versions from the Windows task bar). Would that be a better workflow?

@preetipriyanka
Copy link

preetipriyanka commented Jul 13, 2019

  • Open control panel and uninstall nvm and node.
  • install nvm-setup.zip from https://github.com/coreybutler/nvm-windows/releases
  • open command prompt. Enter nvm install @Version. then nvm use version.
  • install yarn. then in command prompt run yarn install or yarn.
  • check the node version by node -v.

@delepster
Copy link

@bmblb
Copy link

bmblb commented Jan 21, 2020

I just had similar issue, but different reason.

D:\> node -v
v12.14.0
D:\> nvm use 8.9.4
Now using node v8.9.4 (64-bit)
D:\> node -v
v12.14.0

// problem
D:\> where node
D:\soft\nodejs\node.exe // <- old nvm used this one
C:\Program Files\nodejs\node.exe // <- new nvm was changing this one

IIRC I had previous nvm version installed to D:\soft and it was changing link D:\soft\nodejs. At some point old nvm stopped working, because npm repository changed location (if it works - don't touch, please). I had to install new nvm, and I guess new nvm refused to change old link, instead it was updating link C:\Program Files\nodejs. So I removed D:\soft\nodejs and it was fixed.

Thanks to @delepster who suggested to uninstall old node, that helped me to spot the problem

@putko
Copy link

putko commented Feb 6, 2020

we installed on three computers today, two of them windows 10 operating system installed and one with windows server. Both machines with windows 10 OS lost their search at startup features but not the one with Windows Server OS. so, you can not type the name of the program you want and see anymore.

Anyone else having the same issue?

@bmblb
Copy link

bmblb commented Feb 6, 2020

@putko this is a windows issue appeared today, confirmed and fixed by MS. see this tweet https://twitter.com/tomwarren/status/1225110095010418689

@subhamg
Copy link

subhamg commented Feb 24, 2020

Workaround:
Renamed "C:\Program Files\nodejs" to "C:\Program Files\nodejsx",
Then from an elevated cmd called "nvm use 8.9.1" (any version you got should work..) and it started to work.
Problem seems to be if nodejs directory exists, nvm can not change it to a symlink and 'fails silently' would be nice with a fail and an error message stating the problem.

This worked for me.
image

PS > nvm use 11.4.0
Now using node v11.4.0 (64-bit)
PS > node -v
v10.11.0
PS > nvm use 11.4.0
Now using node v11.4.0 (64-bit)
PS > node -v
v11.4.0

This worked for me too.

@Varstahl
Copy link

Had a similar problem with 1.1.7, finally figured out that the settings.txt file is ignored. nvm use would do absolutely nothing, until I manually set NVM_SYMLINK. Also, without SYMLINK set, nvm will try to remove ., which is interesting, to say the least.

The path parameter in the settings.txt, which contains what should be used by default as SymLink, is never read or used to initialize:

nvm-windows/src/nvm.go

Lines 727 to 751 in 88353cf

// Process each line and extract the value
for _, line := range lines {
line = strings.Trim(line, " \r\n")
if strings.HasPrefix(line, "root:") {
env.root = filepath.Clean(strings.TrimSpace(regexp.MustCompile("^root:").ReplaceAllString(line, "")))
} else if strings.HasPrefix(line, "originalpath:") {
env.originalpath = filepath.Clean(strings.TrimSpace(regexp.MustCompile("^originalpath:").ReplaceAllString(line, "")))
} else if strings.HasPrefix(line, "originalversion:") {
env.originalversion = strings.TrimSpace(regexp.MustCompile("^originalversion:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "arch:") {
env.arch = strings.TrimSpace(regexp.MustCompile("^arch:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "node_mirror:") {
env.node_mirror = strings.TrimSpace(regexp.MustCompile("^node_mirror:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "npm_mirror:") {
env.npm_mirror = strings.TrimSpace(regexp.MustCompile("^npm_mirror:").ReplaceAllString(line, ""))
} else if strings.HasPrefix(line, "proxy:") {
env.proxy = strings.TrimSpace(regexp.MustCompile("^proxy:").ReplaceAllString(line, ""))
if env.proxy != "none" && env.proxy != "" {
if strings.ToLower(env.proxy[0:4]) != "http" {
env.proxy = "http://"+env.proxy
}
web.SetProxy(env.proxy, env.verifyssl)
}
}
}

@anton-dealmeida
Copy link

anton-dealmeida commented Mar 13, 2020

Latest version of Windows 10 Pro where I went through a fresh install I encountered the same issue.

My usual steps to setting up my machine is:

  1. Install primary dependencies (NodeJS and Docker)
  2. Install IDE (Visual Studio 2019 at this point with .NET, NodeJS and Python development deps)
  3. Install additional dependencies like Windows Terminal, PL fonts, nvm, tmux, WSL2, etc...

@ituasdu is correct in his assertion, when I renamed my nodejs file it allowed me to use nvm use and actually set it. Otherwise it would succeed falsely and tell me version set and so forth but it didn't set the version and I'm stuck with the LTS that was installed initially.

I know there is actually a line saying we should uninstall the existing node that I missed the first time around on the README.md but having used nvm-windows before I didn't check it again I just installed it via chocolatey and forgot about that. (is it possible to just do the npm uninstall as part of the install for chocolatey or to just detect if there is one and to prompt the user to uninstall it first before allowing them to install nvm?)

@lackovic
Copy link

lackovic commented Mar 13, 2020

(is it possible to just do the npm uninstall as part of the install for chocolatey or to just detect if there is one and to prompt the user to uninstall it first before allowing them to install nvm?)

I think it is possible: this request should be made to the Chocolatey nvm package maintainer.

@lucya lucya closed this as completed Mar 13, 2020
@azterizm
Copy link

azterizm commented Jun 6, 2020

It happens when you have Node separately installed on your machine (from website or package manager). Uninstalling them and installing through nvm should solve the problem.

@devna13
Copy link

devna13 commented Sep 9, 2020

I'm having same problem and using PS in admin mode doesn't resolve the issue. (Windows 10.0.18363)

image

@larrybahr
Copy link

Can confirm @ituasdu solution worked for me on Windows 10.

@foman
Copy link

foman commented Jun 3, 2021

At the end, I have to manually edit System environment variable NVM_SYMLINK.

@davidwterry
Copy link

Workaround:
Renamed "C:\Program Files\nodejs" to "C:\Program Files\nodejsx",
Then from an elevated cmd called "nvm use 8.9.1" (any version you got should work..) and it started to work.
Problem seems to be if nodejs directory exists, nvm can not change it to a symlink and 'fails silently' would be nice with a fail and an error message stating the problem.

3 years later and this is still the right answer. THANK YOU!

@JiaQi-0827
Copy link

C:\Program Files>nvm version
1.1.7

C:\Program Files>nvm ls

14.17.3

C:\Program Files>nvm use 14.17.3
Now using node v14.17.3 (64-bit)

C:\Program Files>node -v
v8.17.0

C:\Program Files>npm -v
6.13.4

C:\Program Files>

@marcoshevaristo
Copy link

@ituasdu 's answer solved the problem thank you! 3 years have passed and the issue still exists, surprisingly. I wonder if any of the accepted PR's since last release would solve this problem, 3 years is a pretty big release window.

@coreybutler
Copy link
Owner

There is nothing to "fix". When Node.js is previously installed at C:\Program Files\nodejs, the Node installer sets permissions that prevent it from being overridden by other installer processes. For an analogy, it's a little bit like trying to install a new version of Microsoft Word in the same directory as an old version of Microsoft Word is installed in. This is why the README, since day 1, has specifically mentioned that prior versions of Node.js should be uninstalled before installing NVM4W. The installer will attempt to do this, but permission conflicts can prevent it from working.

Repository owner locked as resolved and limited conversation to collaborators Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests