4

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?

Srini V
  • 11,045
  • 14
  • 66
  • 89
Dave
  • 15,639
  • 133
  • 442
  • 830

4 Answers4

2

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
Kalana Demel
  • 3,220
  • 3
  • 21
  • 34
  • Per my question, I'm running Amazon Linux, so the first ocmmand you listed fails with teh output "sudo: apt-get: command not found" – Dave Nov 03 '17 at 13:48
  • SoI notice you are using "nvm" whereas I was trying to get this to work with "npm" and "node". Do you know why my "npm" command is failing? Is it impossible to run such a command on the version of Linux i use? – Dave Nov 03 '17 at 19:51
  • npm should work given there is no other issue with the system. But using npm alone you might run in to the same kind of issues again in the future, with nvm it's much easier manage multiple versions of node with a single command and the chance of a broken package is minimal. – Kalana Demel Nov 04 '17 at 01:08
  • I woudl like to tackle this issue head on instead of finding a work-around. How do I figure out why npm isn't working? – Dave Nov 04 '17 at 17:37
  • @Dave, nvm does install npm. Node cannot work without it (nvm != npm). nvm is more like apt or yum specifically geared towards managing multiple node versions. When you use `nvm install` it just install node in a more manageable way, nvm has little to do with npm. you can check with `npm -v` after the curl command. We're only using nvm to manage node, you must continue to use npm for all other tasks like installing pachages. But for the sake of more information I'll add how to install and update node and npm without nvm as well. – Kalana Demel Nov 05 '17 at 02:29
0

check the releases notes of node https://nodejs.org/en/download/releases/ you can download older version from this site

BetoSEC
  • 31
  • 4
0

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.

Argus Malware
  • 773
  • 7
  • 19
  • Thanks but I don't want to use nvm. I wanat to figure out why my current installation isn't working. There's another node version out there ... need to figureo ut how to find it. – Dave Nov 09 '17 at 17:59
  • do node -v it will show version if installed, then i will tell you the rest steps – Argus Malware Nov 09 '17 at 18:00
0

I suggest you to consider the use of nvm, that allow you to switch to all installed node version, further information on https://github.com/nvm-sh/nvm

lucacld
  • 11
  • 2