sudo npm i npm or sudo npm install npm#latest -g throws an error of EACCES:permission denied - node.js

I have npm v 5.6 and I installed node version 10.1 so the current npm doesn't support node version while updating npm I am getting EACCES permission denied error. I tried removing npm directory and updating via several command the npm version is stuck at 5.6. Help!!
Using Ubuntu v16.04 LTS.
I tried installing different nodejs version too but it also doesnt change npm version(npm v5.6).
visit here for the screenshot

I'd recommend using a version manager (such as nvm) to install multiple versions of Node.js and switch between them at will.
First off, make sure you have git and the build-essential package installed:
sudo apt-get update
sudo apt-get install build-essential git
Then install nvm with cURL (run this command in your terminal):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
This will clone the nvm repository to ~/.nvm and will make the required changes to your bash profile, so that nvm is available from anywhere in your terminal.
Reload your bash profile:
source ~/.bashrc
and verify the install by typing:
command -v nvm
which should output 'nvm' if the installation was successful.
(if this doesn't work, just close, then reopen your terminal)
And that’s it, nvm is installed and ready to be used.
Now, to download, compile, and install the latest release of Node, run the following from your terminal:
nvm install node
And then in any new shell just use the installed version:
nvm use node
Finally, verify the correct version is being used:
node -v
=> 10.5.0
There's a lot more to using nvm, such as installing multiple Node versions.
You can read more about that here: https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/
HTH

Related

Node versions do not match: node vs. sudo node -v ... WSL2 Ubuntu 22.04.1

As you can see in the image below, I see two different versions of node depending on which command I run.
I need the newer version, but npm sees the old version.
Many times I've removed, purged, reinstalled, etc.
I tried installing nvm as root and setting the node version there, but that didn't help either.
If I use apt install nodejs instead of nvm, it tells me that I already have the newest version, which it believes is 12.22.9.
How do I get npm to recognize the newer version (18.12.1) of node that I installed via nvm?
It is because you have a different version of the Node.js which is installed for the root and that particular user.
First, you need to uninstall Node.js:
sudo apt-get remove nodejs
or
sudo npm rm npm -g
If you have any problem with the above commands, then after running which node command, go to that directory, and run the following commands:
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Do the same thing for the current user if needed.
The default Ubuntu/Debian package manager does not have the latest Node.js, and that's why whenever you try to install Node.js with apt install nodejs it says you have the latest version.
According to the official Node.js documentation, for installing the latest version, you should follow these steps:
Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
P.S: No need to run npm or node with sudo. Therefore, I highly recommend you to not use every command with sudo.

How do I find the old version of node js?

I'm trying to install "n", the nom helper on Amazon Linux. I'm having difficulty. It seems I have an old version of the node somewhere but I can't figure out where. When I run
npm install -g n
I get the below error ...
[myuser#mymachine ~]$ sudo /usr/local/bin/npm install -g n
ERROR: npm is known not to run on Node.js v0.10.48
You'll need to upgrade to a newer version in order to use this
version of npm. Supported versions are 4, 6, 7, 8. You can find the
latest version at https://nodejs.org/
[myuser#mymachine ~]$ npm -v
5.4.2
╭─────────────────────────────────────╮
│ │
│ Update available 5.4.2 → 5.5.1 │
│ Run npm i -g npm to update │
│ │
╰─────────────────────────────────────╯
But notice that when I run
[myuser#mymachine ~]$ node -v
v8.8.1
it tells me I have v8.8.1 installed, which is what I intended. How do I purge the old, unwanted version of the node so I can install my helper?
Easiest solution would be to try the following to cleanup your node issues and reinstall a clean version.
First remove everything related to node
sudo apt-get purge --auto-remove nodejs npm
UPDATE For yum:
yum clean all
yum -y remove nodejs
Remove these leftover files and folders as well
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules
Then install node back with nvm,
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
//To uninstall a node version
//nvm uninstall <current version>
nvm install 8.8.1
nvm use 8.8.1
//check with
node -v
npm -v
//**UPDATE**: Install your package
npm install -g n
And all should work.
UPDATE : Install Without NVM
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash -
yum install nodejs
node -v
//Install your package
npm install -g n
check the releases notes of node https://nodejs.org/en/download/releases/ you can download older version from this site
An alternative to installing Node.js through apt is to use a specially designed tool called nvm, which stands for "Node.js version manager".
Using nvm, you can install multiple, self-contained versions of Node.js which will allow you to control your environment easier. It will give you on-demand access to the newest versions of Node.js, but will also allow you to target previous releases that your app may depend on.
To start off, we'll need to get the software packages from our Ubuntu repositories that will allow us to build source packages. The nvm script will leverage these tools to build the necessary components:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
Once the prerequisite packages are installed, you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download it with curl:
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
And inspect the installation script with nano:
nano install_nvm.sh
Run the script with bash:
bash install_nvm.sh
It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.
To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:
source ~/.profile
Now that you have nvm installed, you can install isolated Node.js versions.
To find out the versions of Node.js that are available for installation, you can type:
nvm ls-remote
Output
...
v5.8.0
v5.9.0
v5.9.1
v5.10.0
v5.10.1
v5.11.0
v6.0.0
As you can see, the newest version at the time of this writing is v6.0.0. You can install that by typing:
nvm install 6.0.0
Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:
nvm use 6.0.0
When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:
node -v
Output
v6.0.0
If you have multiple Node.js versions, you can see what is installed by typing:
nvm ls
If you wish to default one of the versions, you can type:
nvm alias default 6.0.0
This version will be automatically selected when a new session spawns. You can also reference it by the alias like this:
nvm use default
Each version of Node.js will keep track of its own packages and has npm available to manage these.

Error: npm is known not to run on Node.js V4.2.6

how can I solve the following error? I use Ubuntu 16.
When I run any npm command such as "npm run dev" I get this error:
ERROR: npm is known not to run on Node.js v4.2.6 Node.js 4 is
supported but the specific version you're running has a bug known to
break npm. Please update to at least ${rel.min} to use this version of
npm. You can find the latest release of Node.js at https://nodejs.org/
First, Uninstall completely nodejs and npm.
sudo apt remove nodejs npm
Then, reinstall it over the link below:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Refer: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
You can try downgrading the node version to switch from the bugged version using the following, upgrading also works if your app supports latest versions.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
nvm install 4.2.5
nvm use 4.2.5
//check with
node -v
//To uninstall a node version
nvm uninstall 4.2.6
I just had this issue on Ubuntu 16. Use n to update to the latest version
sudo n latest
That should settle it.
I download latest install package from https://nodejs.org/en/ and reinstall it. Solve it!
You can also use NVM - I did this to solve the same problem.
first type
nvm ls-remote to view the latest versions available,
then
nvm install [version] (I used v8.7.0)
everything should be fine after that.
I had a similar problem but my project is part of a bigger system so neither switching to nvm instead of npm nor upgrading my version of Node.js were options.
However, moving npm backwards to a previous version was an option. I found 4.6.1 worked without complaint.
sudo npm install -g npm#4.6.1
This version of npm did not complain.
I fixed the same issue with Ubuntu 16.04 by using following commands step by step.
Uninstall nodejs and install version 8.0
$ sudo apt remove nodejs npm
$ curl -o-
https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
$ nvm install 8.0
$ nvm use 8.0
$ node -v
v8.0.0
Get latest release with
$ nvm install node
Then run the following
$ nvm alias default stable_node_version

Please update your Node runtime to version >=0.12.x

Hi i'm working with ionic to build hybrid html app.
Every command i'm running i get the following warning:
******************************************************
Upgrade warning - for the CLI to run correctly,
it is highly suggested to upgrade the following:
Please update your Node runtime to version >=0.12.x
******************************************************
If you can please advise how should i update the node runtime version
This is just asking to upgrade your Node. I normally use nvm with command nvm install <version> && nvm use <version> or you can use node helper as follows:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable // for stable version
sudo n 0.12.7 // for specific version like v0.12.7
// check the node version after install
node -v
To install Node.js v5.x on either Ubuntu or Debian:
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_5.x | bash -
apt-get install -y nodejs
It depends on how you have installed node.js to your computer. You can either go to https://nodejs.org/ and get the updated version, or you can use Node Version Manager (NVM) which allows you to control multiple node versions at once.
I would recommend using NVM, as this avoids having to install nodejs with sudo, which can lead to other problems down the line.
I use command:
sudo npm cache clean
sudo npm install -g cordova
sudo npm install -g ionic
and it works for me.

How to upgrade Node js version to 0.12.4 on Ubuntu

I want to upgrade Node JS version on Ubuntu.
I tried many commands but its version is still the older i.e v0.10.37.
I tried:
sudo npm install -g n
sudo n install 0.12.4
sudo n use 0.12.4
Also tried with nvm but non of them works for me. How can I upgrade Node Js version to 0.12.4?
Use npm in order to upgrade node
First Clean the cache and try
sudo npm cache clean -f
sudo npm install -g n
sudo n 0.12.4
Then create a symbolic link(It is needed only sometimes, first try with these three commands. If it doesnot work add this.)
It will be updated to 0.12.4 Version.
It could be enough just to install n module:
sudo npm install -g n
and then simply run:
sudo n 0.12.4
The trick is that it may not be updated in your current terminal session. So you can simply open one more tab in your terminal or just another terminal and check your nodejs version by:
node --version
That's it, output will be v0.12.4
The official doc from nodejs repository points to this : https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories#installing-node-js-v0-12
Just follow it and you'll have the 0.12.4.
Try running this in terminal:
nvm install 5.10.1
nvm use 5.10.1
The version may be change.
Cheers!
Execute following comand to upgrade nodejs to 0.12.x
Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
Then install with:
sudo apt-get install -y nodejs
Just ignore warning. By executing both commands it worked for me on Ubuntu 14.04
On Ubuntu 16.04
There is no special or dedicated comand to upgrade node version. The correct way to install or upgrade node on ubuntu is:
1) download the distribution you wish from nodejs official site, move the file into a known path
2) open a terminal and run: >sudo tar -C /usr/local --strip-components 1 -xzf "known path/name_of_the_distribution_file...gz
3) test if everything is ok: open a new terminal and run node --version. It should echo the version you downloaded and installed/upgraded.

Resources