404usernamenotfound
404usernamenotfound

Reputation: 191

Install multiple versions of Node.js on Windows without using NVM for Windows

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

Answers (5)

Moika Turns
Moika Turns

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.

  1. install java / maven

  2. 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.

  1. create a .bat file say 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

Jacob
Jacob

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

Adin Sijamija
Adin Sijamija

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

Juan Silup&#250; Maza
Juan Silup&#250; Maza

Reputation: 961

  1. Install here:

install on disk C

  1. Delete %NVM_HOME% and %NVM_SYMLINK%
  2. Add path relative

enter image description here

  1. Enjoy :)

Upvotes: -1

Rich N
Rich N

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:

  • With admin, install the first version you want to use. Copy the c:\Program Files\nodejs folder somewhere where it won't get deleted on a new install: say c:\nodejsbackups\v10\nodejs if it's version 10.
  • Install the second version you want to use, and copy the nodejs file to the same place, say c:\nodejsbackups\v14\nodejs.
  • Also copy it to a place you will run it from and where you have write access, say c:\nodejs if you have write access on the c: drive, or your user profile somewhere if not.
  • Still with admin rights, edit the system Path environment variable (NOT the user path). Find the entry to c:\Program Files\nodejs and remove it. Add an entry for c:\nodejs. Or just edit it.
  • I found that to get Visual Studio node apps to work I then had to also uninstall the original node using Control Panel/Programs and Features.

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

Related Questions