Install Node.js to install n to install Node.js? - node.js

I have a problem understanding the use of n. Basically, it is clear that it is a version manager for Node.js such as nvm.
But in contrast to nvm, which is basically a shell script, according to the documentation you are encouraged to use npm to install n:
$ npm install -g n
What I don't get is: For having npm at hand you need to install Node.js. Why would I install Node.js manually to use npm to then be able to install Node.js using n?
To put my question in other words: Why does n suggest installing using npm, if its main purpose is to install Node.js, which includes npm?

tl; dr
# Installs n and the latest LTS Node.js version to ~/n.
# For bash, ksh, zsh, modifies the respective user-specific shell-initialization file to
# define env. variable N_PREFIX and append $N_PREFIX/bin to the $PATH.
curl -L https://git.io/n-install | bash
I feel your pain. Installing Node.js to then install n to then manage Node.js installations is indeed a strange setup.
It would indeed be great to be able to install n by itself first.
I've created a project to support installation of n directly from GitHub; the only prerequisite beyond what n itself needs is git.
Note that you must first remove any pre-existing n / Node.js versions.
The target directory, ~/n by default, must either not yet exist or be empty.
For bash, ksh, and zsh, the relevant shell initialization file (e.g., ~/.bashrc) is automatically modified to define environment variable N_PREFIX and append $N_PREFIX/bin to the $PATH; for other shells, this must be done manually.
Aside from installing n directly from GitHub, it also installs helper scripts for updating n (n-update) and uninstalling it (n-uninstall).
Here are working examples; see the n-install GitHub repo for details:
Installation with confirmation prompt to confirm installing to default location $HOME/n and installing the latest LTS Node.js version:
curl -L https://git.io/n-install | bash
Automated installation to the default location, with subsequent installation of the latest LTS (long-term support) and latest-overall Node.js versions, as well as the latest 4.1.x Node.js version:
curl -L https://git.io/n-install | bash -s -- -y lts latest 4.1
Automated installation to the default location, without subsequent installation of a Node.js version:
curl -L https://git.io/n-install | bash -s -- -y -
Automated installation to custom location ~/util/n, with subsequent installation of the latest LTS Node.js version:
curl -L https://git.io/n-install | N_PREFIX=~/util/n bash -s -- -y

If you prefer, you can install n from source:
cd /tmp
git clone --depth=1 https://github.com/tj/n
cd n
sudo make install
Then you can install the latest stable version of node as follows:
n stable

The n module was created for convenience.
For example, if you wanted to update your version of Node.js from v0.8.0 to v0.10.20, would you rather download a package, extract and compile? Or would you rather type n 0.10.20 and have it instantly installed, while still retaining previous versions of Node for easy switching?
n suggests using npm to install it because n is a module. That is, npm is the easiest way to install it. Node modules have the functionality of being able to run in a shell when installed globally, so that function was utilized to make switching Node versions much easier.

You can also install npm separately from Node.JS; e.g.: on a system without Node.JS:
git clone https://github.com/npm/npm
cd npm
./configure
make
Reference: NPM GitHub project

I had the same question, but have seen the light. 'n' is a handy tool and makes it simple to test different versions of node. Works great on Linux, but no matter how I try to install it on OS X (git clone, then npm install or using user456584's recommended method), when I run it, I always get the same results of "Error: no installed version", even though it installs into
/usr/local/lib/node_modules/n
and
/usr/local/bin/n
Frustrating because I've found this tool to be so handy on Linux.

If you have included your default node bin in the $PATH variable like this
export PATH=/usr/local/Cellar/node/11.5.0/bin:$PATH
then n will not be able to active other node versions. Remove this export from the path and then you can manage the currently active node version by n.

The README for n now has a longer section covering different installation approaches.
Like nvm, n is a bash script. npm is suggested as an easy way to install n if you already have npm, and then you can use n to change the Node.js version. But there are plenty of other approaches for a first install of Node.js. In brief and in no particular order...
You can install n using curl:
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
Or clone the n repo and install from there:
make install
Or use n-install:
curl -L https://git.io/n-install | bash
Or Homebrew:
brew install n
Or MacPorts:
port install n
(Disclaimer: I am the current maintainer of n.)

If you are using n then you should use below command
bash$ sudo n latest

Related

How to install node.js

I did the following:
user#machine:~$ sudo n stable
installed : v12.13.0 (with npm 6.12.0)
user#machine:~$ node --version
v8.10.0
user#machine:~$ which node
/usr/local/bin/node
user#machine:~$ /usr/local/bin/node --version
v12.13.0
I was expecting v12.13.0 to be installed, but node --version reveals v8.10.0.
What did I do wrong? How do I get v12.13.0 installed? FYI I am on Jetson Nano and I'm really just trying to get LTS Nodejs installed and don't know how.
BTW, if I do sudo apt-get install nodejs I only get v8.10.0.
MORE INFO:
user#machine:~$ node --version
v8.10.0
user#machine:~$ sudo node --version
v12.13.0
Seems sudo is affecting this somehow?
(I'm not very familiar with linux, but I'm learning ... sorry if I'm missing "obvious" stuff.)
I worked around the problem by forgoing the use of n.
Here's how to install directly from the dist at nodejs.org.
wget https://nodejs.org/dist/v12.10.0/node-v12.13.0-linux-arm64.tar.gz
sudo tar -xf node-v12.13.0-linux-arm64.tar.gz --directory /usr/local --strip-components 1
Can't comment but try replacing /usr/bin/node with a symbolic link to /usr/local/bin/node. Had similar issue some time ago that ate my brain. Solved it like this.
P.S don't forget to backup
It's very strange...
Could you try something?
mv /usr/local/bin/node /usr/local/bin/node.back
which node
mv /usr/local/bin/node.back /usr/local/bin/node
I just want to see what produce which if you remove the old node version binary.
Also provide more info about file /usr/local/bin/node, is it a symbolic link? If true, to what?
1) Try opening a new shell and checking what version of node you see there.
n installs the node binary by default to /usr/local/bin/node. You may already have had a node binary installed to /usr/bin/node, and your shell cache of known commands (paths) may be running the old one.
Example of problem with bash: https://github.com/tj/n/issues/588
2) If your OS has the command, you can run which -a node to see if you have multiple versions and where they are installed. (Uninstalling the ones you don't want reduces potential for confusion.)
3) Check the location of the intended version is in your PATH. If you are using n, try running n doctor. There are some extra checks that the version of node found is the one that is the one that n installed.

I have installed nodejs on windows how should i use it in WSL?

I am having problem using libraries installed on windows to WSL and vice versa. I don't want to install not just nodejs but other things twice just to use it in WSL and also in normal text editors like VS code, atom, etc.
The complete instruction can be found here set-up-on-wsl
If you are too busy to follow the link, follow these steps in the WSL:
Use curl to install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
For installing NodeJs (lts)
nvm install node --lts
You can also install specific node version. Check all commands uses by typing nvm in your terminal.
Done Node has been successfully installed in your WSL, nvm ls will list all the installations.
You can use the Node installed in your WSL for developing. Point to your working directory and use code . to open VSCode. Also, if you want to access your windows directories you can mount them by using /mnt/<dir>
If you face any issues during installation it is better to use the link I have provided above.
Also note that, the Node installed in the WSL can only be used, iff your working directory is in the WSL or is linked with your WSL(by using mnt).

Deleted nvm now npm is not working

I installed nvm to update my node but then decided to uninstall. After updating my node via website, I am not able to get npm installed despite installing a new version of node and using:
sudo curl -L npmjs.org/install.sh | sudo sh
Here is the message I am getting:
-bash: /Users/SICNARF/.nvm/versions/node/v8.2.1/bin/npm: No such file or directory
I think I just have to change the command from non-existing nvm directory to (wherever its supposed to run).
Node.js version management: no subshells, no profile setup, no convoluted API, just simple.
Installation
npm install -g n
Example
$ n 8.2.1
https://www.npmjs.com/package/n

Why isn't Node Version Manager (NVM) recognized on Windows?

I am trying to downgrade my version of node
I ran:
npm install nvm
and I exported the bin folder to my Windows path variable,
C:\Program Files (x86)\nodejs\node_modules\npm\bin
but I still get:
'nvm' is not recognized as a an internal or external command.
Should I be adding another path to my path variable?
nvm was designed for Linux. nvmw, which is completely different, broke around node v0.10.30. Try NVM for Windows.
NVM can be used to manage various node version :
Step1: Download
NVM for Windows
Step2: Choose nvm-setup.zip
Step3: Unzip & click on installer.
Step4: Check if nvm properly installed, In new command prompt type nvm
Step5: Install node js using nvm :
nvm install <version> : The version can be a node.js version or "latest" for the latest stable version
Step6: check node version - node -v
Step7(Optional)If you want to install another version of node js - Use STEP 5 with different version.
Step8: Check list node js version - nvm list
Step9: If you want to use specific node version do - nvm use <version>
NVM Installation & usage on Windows
Below are the steps for NVM Installation on Windows:
NVM stands for node version manager, which will help to switch between node versions while also allowing to work with multiple npm versions.
Install nvm setup.
Use command nvm list to check list of installed node versions.
Example: Type nvm use 6.9.3 to switch versions.
For more info
As an node manager alternative you can use Volta from LinkedIn.
I created a universal nvm that works on both Unix (bash) and Windows, base on another simple nvm.
It doesn't need admin on Windows, but requires PowerShell 4+ and the right to execute scripts.
https://www.npmjs.com/package/#jchip/nvm#installation
The first thing that we need to do is install NVM.
Uninstall existing version of node since we won’t be using it anymore
Delete any existing nodejs installation directories. e.g. “C:\Program Files\nodejs”) that might remain. NVM’s generated symlink will not overwrite an existing (even empty) installation directory.
Delete the npm install directory at C:\Users[Your User]\AppData\Roaming\npm
We are now ready to install nvm. Download the installer from https://github.com/coreybutler/nvm/releases
To upgrade, run the new installer. It will safely overwrite the files it needs to update without touching your node.js installations. Make sure you use the same installation and symlink folder. If you originally installed to the default locations, you just need to click “next” on each window until it finishes.
Credits
Directly copied from : https://digitaldrummerj.me/windows-running-multiple-versions-of-node/
I will list two ways. You can choose one Whichever works for you.
1. Using installer
Download nvm-setup.zip and unzip the file and install it, keeping the configurations default.
1. Use curl
Copy the below command and run it in your terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
After this reopen/open terminal and check the nvm version runing below command.
nvm -v
And that's it.
If someone is looking for install on Window 11! Not directly relevant here, but might be useful.
It is immaterial if you install NVM (version 1.1.9.) say after the node (16.15.1) is already installed. During the nvm installation process, it asks for the right to manage the existing node version and symlinks that.
Get the version from the GitHub repo, I opted for the zip version.
https://github.com/coreybutler/nvm-windows/releases
Double click the application and it is just a few steps.
1.downlad nvm
2.install chocolatey
3.change C:\Program Files\node to C:\Program Files\nodejsx
emphasized textThe first thing that we need to do is install NVM.
website :
https://learn.microsoft.com/en-us/windows/nodejs/setup-on-windows
So this answer is for windows users that are using git bash or some other console emulator like cmder ... if you're using CMD this solution will not work for you also why? why are you still using CMD?
I know this is a pretty old post but I just achieved this yesterday and wanted to add my answer for anyone looking to do the same.
First check if you have .bashrc profile in your home directory by typing ls -alh ~ (by default this doesn't exist)
if it doesn't exist type this command to generate a .bashrc profile with default values in it cat /etc/bash.bashrc > ~/.bashrc (if it does exist skip this step)
Download and run the nvm install script as provided in the nvm docs page curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash (make sure you do this in your home directory)
then edit the new generated .bashrc profile file you created above; use nano/vim to do that nano ~/.bashrc and add the following to the bottom of the file export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm and save your .bashrc file with the changes.
lastly source your .bashrc file by typing source ~/.bashrc
verify installation nvm --version
and now you have nvm installed and you can use the commands as per https://github.com/nvm-sh/nvm#usage
First off, I use nvm on linux machine.
When looking at the documentation for nvm at https://www.npmjs.org/package/nvm, it recommendations that you install nvm globally using the -g switch.
npm install -g nvm
Also there is a . in the path variable that they recommend.
export PATH=./node_modules/.bin:$PATH
so maybe your path should be
C:\Program Files (x86)\nodejs\node_modules\npm\\.bin
An alternative to nvm-windows, which is mentioned in other answers would be Nodist.
I've had some issues with nvm-windows and admin privileges, which Nodist doesn't seem to have.
I know I'm late here but this may help in the future if someone looking for NVM to install in Windows or linux
run this command in cmd
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Installing nodejs: I need GNU make. Please run 'gmake' instead

I want to install nodejs on my PCBSD 10 system. I have downloaded the src file of latest nodejs. On terminal I ran the command ./configure It runs fine. After that I tried make but its asking on console
I need GNU make. Please run 'gmake' instead.
Then I tried gmake the terminal says
CORRECT>gmake (y | n | e | a)?
I pressed y then again it says "I need GNU make. Please run gmake instead"
How to install nodejs???
If you install it using the FreeBSD ports system, that will take care of these details for you.
If you haven't installed the ports tree, run the following command as root;
svnlite checkout https://svn0.us-west.FreeBSD.org/ports/head /usr/ports
Note that there are some subversion mirrors for FreeBSD. Choose the one closest to you. After the initial checkout, you can update the ports tree by running the following command as root;
svnlite update /usr/ports |& less
When the ports tree is installed and up-to-date, you can install node by running the following commands as root:
cd /usr/ports/www/node
make install clean
This will first install the ports that node depends on (gmake and python2) and then node itself.
You might also want to install the node package manager from the www/npm port.

Resources