Nvm-windows: mklink is not reliable on windows 10

Created on 4 May 2017  ·  3Comments  ·  Source: coreybutler/nvm-windows

My Environment

  • [ ] Windows 7 or below (not truly supported due to EOL - see wiki for details)
  • [ ] Windows 8
  • [ ] Windows 8.1
  • [X] Windows 10
  • [ ] Windows 10 IoT Core
  • [ ] Windows Server 2012
  • [ ] Windows Server 2012 R2
  • [ ] Windows Server 2016

  • [ ] My Windows installation is non-English.

I have already...

  • [X] read the README to be aware of npm gotchas & antivirus issues.
  • [X] reviewed the wiki to make sure my issue hasn't already been resolved.
  • [X] verified I'm using an account with administrative privileges.
  • [X] searched the issues (open and closed) to make sure this isn't a duplicate.
  • [X] 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
  • [ ] 32 or 64 bit support

Expected Behavior

nvm use <version> should create symlink at C:\Program Files\nodejs or at value provided in path argument in file settings.txt

Actual Behavior

The symlink is not always created, even if I run nvm use from an elevated shell.

Steps to reproduce the problem:

nvm install 6.9.1
nvm use 6.9.1

I'm prompted by elevate.cmd script, I answer yes, the symlink is not created

I don't know if it's related but I run nvm use from powershell.
Also It's kinda random, on some windows 10 I have the problem, on others I don't.
I believe a good workaround would be to test if symlink is created after running cmd.exe mklink. If symlink is not present, run powershell command new-item to create the link

All 3 comments

Do you not actually see the symlink after running nvm use? Have you tried running the command in a standard shell instead of Powershell?

1.Please delete the installation node by window10 uninstall program

2.nvm install

3.modification Environment Variables window(reference)

Chinese interpretation:
1.window10 装nvm要先删掉电脑本身已经装的node,因nvm无法管理window10 已经装的nvm(报修改注册表失败)
2.装完nvm后使用nvm本身装 node
3.修改 NODE_PATH,为C:\Program Files\nodejs;因nvm在“C:\Program Files\nodejs”创建一个软连接,连接到“nvm root”(nvm root指向node实际目录)

@coreybutler : No I do not see the symlink after running nvm use.

Have you tried running the command in a standard shell instead of Powershell?

=> The whole point is to run it from powershell. Indeed I run a script that install lots of dependencies and configure the VM. Here is a subset of the script

$wc = New-Object System.Net.WebClient

# configure repositories
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Get-Packageprovider -Name chocolatey
Set-PackageSource -Name Chocolatey -Trusted

Install-Package 7zip.install -ProviderName Chocolatey -RequiredVersion 16.02.0.20160811
$env:PATH+=";C:\Program Files\7-Zip"

$source = "https://github.com/coreybutler/nvm-windows/releases/download/1.1.3/nvm-setup.zip"
$archive = Join-Path $env:TEMP ($source.substring($source.lastindexOf('/') + 1))

$wc.DownloadFile($source, $archive)

echo "downloaded at: $archive"

7z x -aoa -y $archive "-o$env:TEMP"

#$uninstallScript = (Join-Path $PSScriptRoot uninstall_cmdline.ps1)
#&$uninstallScript -software "NVM for Windows*" | Out-Null

$nvmSetup = Join-Path $env:TEMP "nvm-setup.exe"
Start-Process $nvmSetup -ArgumentList @("/SILENT", "/SP-", "/SUPPRESSMSGBOXES") -Wait
ri $archive
ri $nvmSetup

$localNvmPath = Join-Path $env:APPDATA "nvm"
$defaultNodejsPath = "C:\Program Files\nodejs"
#Add-Path $localNvmPath
#Add-Env NVM_HOME $localNvmPath
ri $defaultNodejsPath -ErrorAction SilentlyContinue -Recurse -Force
nvm root $env:NVM_HOME
nvm install 4.5.0
nvm use 4.5.0
#create manually symlink if problem with nvm use, see https://github.com/coreybutler/nvm-windows/issues/266
#$nodePath = Join-Path $localNvmPath "v4.5.0"
#if ((-Not (Test-Path $nodePath) -or (-Not (Test-Path $defaultNodejsPath))))
#{
#    Start-Process powershell -Verb runAs -ArgumentList "-WindowStyle Hidden", "-Command `"&{ New-Item -Path `'$defaultNodejsPath`' -Value `'$nodePath`' -ItemType SymbolicLink }`"" -Wait -WindowStyle Hidden
#}

You should be able to put this script in a ps1 file and execute it as is. I commented Add-Env and Add-Path functions which respectively add variables to the env and folder location to the PATH. I also commented uninstall script call which basically uninstall nvm if any was installed before. I also commented the workaround I found: create the symlink manually.

@youzaiyouzai666 : I spawn a fresh VM on Windows 10 Enterprise 64bits, there is no previous node installed.

Was this page helpful?
0 / 5 - 0 ratings