9

Issue is very peculiar, I have a version of NodeJS installed in Windows (in program files x86) and a newer version of software downloaded and exe is extracted.

The installed NodeJS (node.exe) 's path is included in system path variable. I added the extracted path to user environment path variable. After doing my bit of RTFM I came to know that in case path variable both system and user environment variables are combined and the system gets the precedence.

Is there any way I can override (or nullify) the system variable's PATH with user variable's path ? or can the precedence of reading variables be changed ?

sij
  • 1,307
  • 7
  • 18
  • 35
  • 1
    using process.env you can get the environment of your system – Deep Kakkar Mar 14 '17 at 13:57
  • The user-related environment variables take precedence over the system-related ones, unless you explicitly tell something else... – aschipfl Mar 14 '17 at 17:14
  • 1
    @aschipfl Not the case for `%PATH%`. System path is concatenated with user path, so system path is searched *first*. See [*Prevent Windows System %PATH% from being prepended to user %PATH%?* - Super User](https://superuser.com/questions/367194/prevent-windows-system-path-from-being-prepended-to-user-path). – Franklin Yu May 16 '18 at 20:14

2 Answers2

4

In cmd, type

set PATH=D:\Path_To_Local_Folder;%PATH%
node

It will start node from your local folder.

mihai
  • 37,072
  • 9
  • 60
  • 86
  • again PATH is resolved as taken from sys variables first and then user variables and then only shell variable – sij Mar 14 '17 at 18:27
  • that's not correct...in the command line you only have one PATH variable that you can modify, for the current cmd session. – mihai Mar 15 '17 at 08:35
  • C:\Users\sij>node -v v4.4.3 C:\Users\sij>set PATH = C:\Users\sij\Downloads\git\bin;C:\Users\sij\ Downloads\node-v6.10.0-win-x64\node-v6.10.0-win-x64;%PATH% C:\Users\sij>node -v v4.4.3 – sij Mar 16 '17 at 14:15
1

Using Powershell you can set the folder Node runs from so that it picks up the new version of Node for that instance of Powershell.

  1. Open Powershell
  2. Set the path variable to be your node folder $env:Path = "C:\yournodefolder";
  3. Running node --version should now display the version of node from your new folder.
ryibas
  • 11
  • 2