How can I install node.js without putting it in the path? - linux

I have an older node.js installed on my mac, that is still needed, but for some other application a newer version is needed as well that I would like to access using full path, so that the node command uses the older version.
So is there a way to compile from source or install node.js without modifying the PATH?
PS.: newer npm is needed for the newer node.js

The nvm (node version manager) package is designed to allow you using multiple node versions without modifying the system PATH.
You even can specify the required node version per project directory.

Related

Unable to downgrade Node to specific version

I am building a sample application in which I need to use Node Version v9.11.2 and npm 4.0.0. Currently I have Node Version v16.4.0 installed on my system. I tried to install the specific version by uninstalling the latest version and installing version 9.11.2 from official website
Problem: The problem is I can uninstall the latest version without any problem but when I try to install older version(9.11.2) the command gets opened and it does nothing. I also tried to install the older version using cli commands ie. npm install -g node#9.11.2, it installs the version but on checking the version using node -v, it still shows the latest version(16.4.0)
Below are the screenshots for better understanding
Installed version 9.11.2 but showing 16.4.0
Any Solution please ?
Is using docker a possibility? If so you can simply get a docker image of the required version and use if from there.
Another way is to use NVM which is a really useful tool to manage nodejs versions. I'm including their github repo for your convenience:
https://github.com/nvm-sh/nvm
A good option is to use NVM: https://github.com/coreybutler/nvm-windows (Windows) or https://github.com/nvm-sh/nvm (unix, macOS). With NVM you can enable different versions of node on the same machine and switch from one to another, usually it takes care of managing the installed packages and adding them to its own management system.

Co-Existience of two different NodeJS for same project

I am quite new to NodeJS and am planning to upgrade NodeJS version for my current project. The most recent NodeJS LTS is installed using NVM.
I need to keep switching between the current LTS that i am using and the new LTS that has been installed. I understand that i can do 'NVM use' for this purpose. npm-shrinkwrap.json is being used to lock down the npm package dependencies.
I am planning to follow the below approach both in my dev machine and build machine;
Is it okay? If not, please suggest a best approach.
nvm use latest_LTS
Update the package.json to pick the version which is supported by
latest_LTS
npm install
generate testing_build
Whenever i need to generate a build for current release (with the previous LTS NodeJS)
nvm use currently_used_LTS
clear the node modules
npm install (Release npm-shrinkwrap.json)
generate release_build
Thanks
In theory that should work.
However have you considered the option of just doing a point release for the current release_build that does nothing except version-bump node?
You may find (after re-running your tests) that the latest version of node is backwards compatable with release_build (or only requires minor fixes), and you can simplify your life by porting everything to the latest node version, rather than constantly switching

Webpack failed to compile react code after upgrade to node v8 (on Ubuntu 16)

After upgrading from node v7 to node v8, webpack failed to compile my react code.
It said that some node_modules are not found. Note: This issue does not happen on Windows.
I tried several ways from refreshing node cache & npm_modules to double-checking $NODE_PATH, but still failed to make it work. Looks like an compatibility issue of node v8 and webpack (or some ES6 syntax).
Temporarily I reverted back to node v7 to make it work.
Does anyone encounter this issue?
When you install a new Node version then you need to make sure that you install all modules that you want installed globally using that new version (you need to have both node and npm in your PATH with that new version first before any other version of node and npm that you might have in your PATH or this will likely not work as expected). Then you need to rebuild all locally installed modules (you may need to remove node_modules directory in some cases to make sure that everything is built from scratch).
One issue that is quite common when you have multiple Node versions installed from the binary packages (using either binary tarballs or nvm etc.) is that the npm that gets installed has a general shebang line #!/usr/bin/env node instead of a specific path like #!/opt/node-v8.0.0/bin/node which would be the case if you built Node from the sources yourself.
This means that you can sometimes go into trouble by running npm with global path that would use the wrong version of Node, leading to some issues that can be hard to notice.
The least problematic Node installation in my experience is building it from sources, installing in a versioned directory and explicitly adding it to PATH before installing the modules globally, before local npm install and before running the project that you want to be using that specific Node version. That way you can make sure that you're not using any files that could be left overs from older versions, like would be the case with installing under a common /usr/local prefix.
You can take a look at my tutorial for more details and other options to install Node:
https://gist.github.com/rsp/edf756a05b10f25ee305cc98a161876a
In general what you described is usually caused by clashing installations of Node.

I installed node.js v5.12.0 but the version showing v0.12.2

I installed Node.js from (https://nodejs.org/dist/latest-v5.x/node-v5.12.0-x64.msi), but the issue is , its showing version v0.12.2 instead of v5.12.0 which is required.
I try to update the node.js 5.2 installer but still showing version v0.12.2.
I have uninstalled Node.js and reinstall node-v5.12.0-x64.msi but still it’s not updated. Due to this am not able to run further commands for Ionic environmental setup.
Open a terminal and type where node
It should point to an old version of node (v0.12.2) still installed on your computer, for example C:\bin\node.
As Node.js is portable, you can have multiple versions on your computer.
If it cannot be uninstalled, simply delete C:\bin\node folder.
Then:
Open Windows System Properties/Advanced system properties
Click on Environment variables and edit PATH variable
Remove inside its value the path of the old version of node (C:\bin\node in our example).
Re-install Node v5.
Close your terminal and open a new one then type where node, it should point to Node.js v5
Most likely, you have an old Node version for x86 platform, and you are installing a newer version for 64 bit. Remove the path to the x86 from the Paths env variable, or move it to after the 64 bit path.
Solution:
List node.js installatios using nvm:
nvm ls
High chance the version you tried to install is also listed
Select the version to use using nvm
nvm use
(Not a direct solution)
You can try to install using nvm
Uninstall nodejs and follow the instruction from https://github.com/coreybutler/nvm-windows

How to upgrade node.js on Windows?

I already have Node.js v0.8.0 running on Windows. Can I just run the latest installer to upgrade it to v0.8.4? I am afraid it will break existing third party modules on my machine.
Yes, you just install the latest version. Generally you shouldn't have any compatibility problems if you are already using the same major version (e.g. Version 0.8.x). If you are concerned about changes, you can always check the changelog for each version (link to changelog is on node.js download page at nodejs.org). That should tell you of any big changes (i.e API changes, etc).
For the record, I have just gone through the process, and it is painless even if you upgrade to another major version.
I have moved from 0.8 to 0.10, using the .msi package, overwriting the one installed on my system. Package problems were all fixed with npm update -g. Worked like a charm.
In case it does not work like a charm:
npm cache clean usually fixes the problem. Once the cache is empty, just run npm update -g again.
In case you really run into trouble:
Delete the modules you have installed globally, then reinstall them. Here's how:
Take stock of what you have:
npm list -g --depth=0 lists all top-level packages, with version numbers.
npm list -g --parseable --depth=0 > npm-global-modules.txt writes them to a file in your cwd.
Any strange stuff you didn't install yourself has probably been installed by another module (rare, but I have seen it happen). Remove those modules from the list. Also remove the module "npm".
In an editor, format the output for the command line by replacing \n?[^\n]+[\\/] (regex) with a single space.
(I didn't get this to work with findstr in a pipe, hence the roundtrip to the editor. You can also do it manually, of course ;)
Delete all modules. On Windows, delete (or rename) the %appdata%\npm directory. For other OS, see Command to remove all npm modules globally?
Reinstall the modules with npm install -g [your module list here]. Don't forget to npm cache clean before you do it.
I don't have experience with node on Windows, but I have just upgraded node & modules on my Mac, so this is just a general answer:
If you install v0.8, you might break your existing node modules, if they use deprecated functions, etc. The problem is that npm only checks your version of node while modules are being installed, not at run-time.
To be on the safe side, you need to find the global node_modules folder on your machine, back it up to somewhere, then delete and reinstall the modules. You will need to do the same thing for the node_modules folders in the apps you are using. (Assuming you have package.json files, reinstalling these should be easy.)
In practice, I don't think any of the modules I was using were actually incompatible. Good luck.
Yes. You can upgrade your node.js version to the latest by running the installer for latest node.js version at https://nodejs.org/en/. I upgraded mine from 4.4.4 to 8.11.2 running the installer.
Unless you're using a module that relies on an actual bug that was present in 0.8.0 and was fixed by 0.8.4, you're OK. There were no API changes in between those two versions (and the node team is too smart to introduce such changes in a minor release).
Currently upgrading to 4.4.*. I just used to installer from the nodejs.org website and that upgraded everything works just fine.
Just go to nodejs site & download it. You can install it directly without any hesitation. If you have any dependency on earlier version then check change logs.
JUST GO TO
nodejs.org
INSTALL THE LATEST STABLE VERSION (Recommended For Most Users)
and then run
npm install node
Now, you are good to go
You can even check the version of NodeJS using command
node --version
Best way to install node on windows is by using nvm-windows, so you can quickly switch between versions if you need to. This is analogous to the best way of installing node on linux and max, ie with nvm.
But Benjen is right (how could he not be with all his scouting experience) that you can just install a different version of node, and your version will update. Your npm dependencies may have to be reinstalled, and any extensions that aren't managed by npm may need to be recompiled, but this will be true no matter how you change your node version.

Resources