Reputation: 191
I haven't been able to find any questions/answers regarding how to install two versions of Node.js (such as v10 and v14) on the same computer without using NVM. I can't use windows-nvm because it requires admin privileges, and I'm working on a company laptop as a standard user.
I need to be able to install multiple different versions of Node.js because different projects under the same company use different versions of Node.js as a necessity.
Is the only way to uninstall the installed version and install a new version every time? Is there any way I can have v10 under C:\Program Files\node10, and v14 under C:\Program Files\node14?
To be clear, the admins are willing to grant me specific privileges or install any software needed in order to get this working. We have tried using something called RunAsTool to try to let me run NVM as an admin, but this doesn't work because of its limitations.
Another option would be to grant me admin rights to any files and directories needed for NVM to function, but there is no list of those files/folders that I can find.
A third option would be to simply install two different versions, but when you install a new version, the previous version gets removed, even if it's installed under an unusual path like C:\Program Files\node16.
Upvotes: 10
Views: 21272
Reputation: 801
I also encountered resistence to nvm because it rubbed the local security software up the wrong way.
One alternative to nvm (which is super easy) is to install the maven build tool (requires java) and use the plugin from com.github.eirslett
to install whatever combinations of npm / node are required.
Once these are installed either select the one that's wanted by updating the PATH environment variable with a batch file or via Windows settings.
install java / maven
create a simple pom that will run the plugin, below is just a sketch of the key part, you'll need to craft your own simplest pom possible and the maven command that invokes the plugin
...
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>install-node-and-npm</id>
<phase>install</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v16.20.1</nodeVersion>
<npmVersion>8.19.4</npmVersion>
<installDirectory>C:\adhocnode/NODE16</installDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
This will do the heavy work of fetching the requested version of node. Alter the versions and target folder as required.
cmdWithAdhocNode.bat
that launches a command window with a path updated accordingly like so:PATH=C:\adhocnode\NODE16;%PATH%;
cmd.exe /k "prompt $$ "
Could host muliple versions locally and switch between them. It may seem a bit clunky but once the plumbing is installed it's quite frictionless.
Upvotes: 0
Reputation: 1
Had the same issue on a teamcity server, solved it by making a powershell script and adding it to the deployment run.
$url = "https://nodejs.org/dist/v20.11.1/node-v20.11.1-win-x64.zip"
$outputDir = (Get-Location).Path
$extractedFolderPath = "$outputDir\node-v20.11.1-win-x64"
# Download the file
Invoke-WebRequest -Uri $url -OutFile "$outputDir\node-v20.11.1-win-x64.zip"
# Unpack the zip file
Expand-Archive -Path "$outputDir\node-v20.11.1-win-x64.zip" -DestinationPath $outputDir
$env:PATH = "$extractedFolderPath;$env:PATH"
# Run npm install from the Node.js installation directory
npm install
# Run npm build
npm run build
Write-Host "Node.js has been downloaded, unpacked, npm install, and npm build has been executed."
Upvotes: 0
Reputation: 734
I had a similar issue with nvm. I couldn't afford to run it as admin because it was going through TeamCity for the nvm use command. There is no clean solution with nvm. However, you can use Volta as an alternative. It doesn't require admin privileges.
Upvotes: 3
Reputation: 961
Upvotes: -1
Reputation: 9475
There's no easy way to do this, I think. Broadly you need two things to get node working on Windows: the nodejs folder with the executable in it, by default c:\Program Files\nodejs, and the path to that to be on the system path before any other node paths.
Unfortunately both writing to c:\Program Files and changing the system path require admin rights.
However, there is a somewhat clunky workaround. The overall idea is to put the nodejs folder somewhere where you have write access, point the system path at it, and it should run. Then you can switch versions without admin rights by replacing the folder. To do this:
Now fire up a command prompt and do node --version
and npm --version
and you should see the second version is working.
To switch versions, without admin delete c:\nodejs and then copy the first version to there from c:\nodejsbackups\v10\nodejs. Restart your command prompt, issue the same commands, and you should see the first version is now working.
This seems to work on some very limited testing, but I think you need to test it all works for your use cases. There may be programs like Visual Studio that assume node is at c:\Program Files without using the path. In the end it may be better to beg for admin rights.
Upvotes: 6