Can not Install NPM along side with the ROS melodic? - node.js

I am using ROS melodic for my current project but I need to install nodejs for my college work in ubuntu 18.04. When I install nodejs by using the following commands
sudo apt install nodejs
sudo apt install npm
it gives me an error like this.
error
So I installed that dependency but after installing that dependency my ros packages removed. How can I install the npm without losing the ROS melodic?
Thanks in advance !!

I found something on the internet that take me to the solution,
I installed python virtual environment
https://linuxize.com/post/how-to-create-python-virtual-environments-on-ubuntu-18-04/
in that virtual environment I installed nodeenv with the help of pip
https://pypi.org/project/nodeenv/#id73
I created node.js virtual environment in which I installed the NPM without getting any error.
And we can also install nodeenv with the global environment too!

I faced the same problem and solutions were deleting whole ros melodic.
found the solution as follows:
$ sudo apt-get purge nodejs npm
after this command if you installed nodejs it's going to be deleted.
enable the NodeSource repository by running the following curl command:
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
then:
$ sudo apt-get install -y nodejs
the nodejs package contains both the node and npm binaries.

Related

Node Server Unable to Start

Issue: Unable to start Node server
Platform: Bash on Ubuntu on Windows 10
Currently following tutorial that builds a blog on MEAN
Commands ran after installation:
apt-get install npm
npm init
npm install express --save
node server.js
Last command node server.js supposed to start Node server.
But nothing happens on my bash command line.
server.js codes:
command node-v (node version not found):
However, Node is already installed:
Accessing localhost:3000
On Ubuntu (and Debian as well), the correct package to install for Node.js is called nodejs:
$ sudo apt-get install nodejs
However, my experience is that this generally installs an outdated version of Node, which isn't great. It also installs the interpreter with the executable name nodejs, not node as you would expect.
Alternatively, you can add the official binary distribution repositories for Node.js, which allows you to install more recent versions of Node (v6 or even v7). These are also kept up-to-date much better than the Ubuntu/Debian repositories.
The process is documented here, but if you want to install Node v6, you would run this code:
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs
It's probably best to remove any previously installed packages (npm, node, nodejs) before running the commands above.

NodeJs not installing properly - ubuntu 16.06

I have followed This digital ocean tutorial for installing node . and when i tried to run command sudo apt-get install npm it gave me error that
The following packages have unmet dependencies:
npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I removed it completely using This Post and install nodeJs again using This NVM tutorial It ended successfully installing .I made app.js with "hello world" as response and run the command node app.js and when i hit the localhost:3000 it showed Hello world - But once i closed my terminal and run node app.js it failed saying
The program 'node' is currently not installed. You can install it by typing:
sudo apt install nodejs-legacy
while i have done that before . It only runs again if i follow all the steps of nvm installation again
please try below command to install nodejs.
sudo apt-get install -y nodejs
sudo apt-get install npm
sudo npm install n -g
version is:`-- n#2.1.4
*following commands are used to run nodejs program
node
>console.log("Hello World!");
above command print hello world in cmd
ctrl+d is used to terminate from cmd

node not working on Bash on Ubuntu on Windows

I am trying to make node work inside Bash on Ubuntu on Windows.
I am just starting out with using Bash on Ubuntu on Windows, so I am probably doing some newbie mistake.
I have done apt-get install on node
# sudo apt-get install node
Reading package lists... Done
[...]
That command gives reasonable output.
But when I actually try to run the command I get no response whatsoever. No error message, nothing
# node -v
# node
#
What am I doing wrong?
To install NodeJS in ubuntu, install nodejs package:
wget -qO- https://deb.nodesource.com/setup_6.x | sudo bash -
sudo apt-get install nodejs
The package node is not related to NodeJS.

How to install latest node version on Ubuntu?

I want to install the latest node (v6.2.0 at the time of writing) on Ubuntu. But as I do
sudo apt-get nodejs
This installed v0.10.37.
Can you please help me in installing the latest version of node js and also npm latest version?
This is very simple,
Grab the Linux node distribution from here:
https://nodejs.org/dist/v6.2.0/
Open Terminal and type below command:
sudo tar -C /usr/local --strip-components 1 -xzf ~/Downloads/node-v6.2.0-linux-x64.tar.gz
ls -l /usr/local/bin/node
That`s it.
Now check your node version by typing:
node -v
npm -v
One can install any version of node in Ubuntu using above steps.
There is official instruction:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Follow https://deb.nodesource.com/setup_6.x to read shell script before execute above commands.
You always must to know what you run, especially by sudo.
Any version of node install is very easy
Just click Node.js scroll down and go Installation instructions and chose which version you want to install
To Install 12.x version of node:
Open your terminal [Ctrl+Alt+t]
execute below command
Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
or
Using Debian, as root
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
To remove previous version use command
sudo npm cache clean -f
sudo npm install -g n
and then for latest version
sudo n latest
Or for stable version
sudo n stable
By far the most convenient way to install and manage node versions on your machine is the Node Version Manager a.k.a nvm. Just follow the installation instructions in the repo and after you have it installed run
nvm install 6.2.0
I would suggest installing through package manager to make sure it installs with accurate dependencies.
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Also, use NPM
sudo apt-get install npm
to install modules, like so:
npm install express
Install the package through the official download page, in a .deb format. Go ahead and grab the newest version here:
https://nodejs.org/download/release/latest/
Just go ahead and download your desired version and double-click on the downloaded .deb file, and you're good to go. npm comes with nodejs, btw.
RECOMMENDED READING
https://www.npmjs.com/package/npm
EDIT
If you wish to completely reinstall nodejs, check out the script located here:
https://gist.github.com/brock/5b1b70590e1171c4ab54
and check out this:
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
It says Mac OSX, but it'll work perfectly fine in ubuntu, too.
depends on what version of latest nodejs you want to install
if LTS version or current latest version, then from PPA
latest LTS version
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get install nodejs
current latest version
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
apt-get install nodejs
source: https://codesposts.com/ydOAwynW
Install the snap package
The easiest method to install Node.js on Ubuntu is to use the snap package. Just search for node on Ubuntu Software store and install the first one.
Or if you prefer command line:
sudo snap install node --classic
Alternate method: NVM
If you can't use snaps for some reason, like from a WSL environment, then Node Version Manager (NVM) is the way to go. It's safer than upgrading the node packages in Ubuntu to unsupported versions from PPAs or 3rd party repos, which may cause conflicts or breakages in apt package management system. Compared to NVM, manual installations from tarballs are harder to maintain and upgrade. Follow these steps to install the latest node using NVM:
Step 1: Install NVM
Run this command in Terminal:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Step 2: Install node
Once NVM installation is complete, close and reopen Terminal. Then run this command:
nvm install node
Step 3: Check node version
Run these commands:
node --version
npm --version
If everything went well, you'll see the latest node and npm versions as output. That's all, node is installed and ready to run! 😊
Note: This question is similar to the AskUbuntu question "How do I install the latest version of node.js?" and my answer equally applies. I'm reproducing my answer here to ensure a full complete answer exists rather than just a link.
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y nano git curl vim htop gnupg2 && curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && sudo apt-get install -y nodejs
Install NodeJS 14x and npm 7x in Ubuntu 2020 LTS
Install Nodesource: curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Install NodeJS: sudo apt-get install -y nodejs
Install latest npm: npm install -g npm#latest
For certain npm packages to run: sudo apt install build-essential
The easiest way is using a single line command is sudo snap install node --classic
It installs the latest stable node version from snap store.

Cannot install packages using node package manager in Ubuntu

NodeJS interpreter name(node) on Ubuntu has been renamed to nodejs because of a name conflict with another package. Here's what the readme. Debian says:
The upstream name for the Node.js interpreter command is "node".
In Debian the interpreter command has been changed to "nodejs".
This was done to prevent a namespace collision: other commands use
the same name in their upstream, such as ax25-node from the "node"
package.
Scripts calling Node.js as a shell command must be changed to instead
use the "nodejs" command.
However, using nodejs mucks up installing packages using npm. Package installation fails with the following error:
sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read /usr/share/doc/nodejs/README.Debian
How do I make npm understand that nodejs is already installed on the system but the interpreter name is different?
TL;DR:
sudo apt-get install nodejs-legacy
First of all let me clarify the situation a bit. In summer 2012 Debian maintainers decided to rename Node.js executable to prevent some kind of namespace collision with another package. It was very hard decision for Debian Technical Committee, because it breaks backward compatibility.
The following is a quote from Committee resolution draft, published in Debian mailing list:
The nodejs package shall be changed to provide /usr/bin/nodejs, not /usr/bin/node. The package should declare a Breaks: relationship with
any packages in Debian that reference /usr/bin/node.
The nodejs source package shall also provide a nodejs-legacy binary package at Priority: extra that contains /usr/bin/node as a symlink to
/usr/bin/nodejs. No package in the archive may depend on or recommend
the nodejs-legacy package, which is provided solely for upstream
compatibility. This package declares shall also declare a Conflicts:
relationship with the node package.
<...>
Paragraph 2 is the actual solution for OP's issue. OP should try to install this package instead of doing symlink by hand. Here is a link to this package in Debian package index website.
It can be installed using sudo apt-get install nodejs-legacy.
I have not found any information about adopting the whole thing by NPM developers, but I think npm package will be fixed on some point and nodejs-legacy become really legacy.
Try linking node to nodejs. First find out where nodejs is
whereis nodejs
Then soft link node to nodejs
ln -s [the path of nodejs] /usr/bin/node
I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.
You can also install Nodejs using NVM or Nodejs Version Manager There are a lot of benefits to using a version manager. One of them being you don't have to worry about this issue.
Instructions:
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 and install it with the following syntax:
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
This will download the script and run it. 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
. . .
v0.11.10
v0.11.11
v0.11.12
v0.11.13
v0.11.14
As you can see, the newest version at the time of this writing is v0.11.14. You can install that by typing:
nvm install 0.11.14
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 0.11.14
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
The comeplete tutorial can be found here
Install nvm first using:
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
Run command
source ~/.profile
Now run this and this will show will all installed or other versions of packages:
nvm ls-remote
Installed packages will be in green. Install whatever version you want:
nvm install 6.0.0
Check where is not installed:
which node
Check current version:
node -v
n=$(which node);
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs-legacy
source ~/.profile
Combined the accepted answer with source ~/.profile from the comment that has been folded and some clean up commands before. Most likely you will also need to sudo apt-get install npm after.
for me problem was solved by,
sudo apt-get remove node
sudo apt-get remove nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
alias node=nodejs
rm -r /usr/local/lib/python2.7/dist-packages/localstack/node_modules
npm install -g npm#latest || sudo npm install -g npm#latest
Here's another approach I use since I like n for easy switching between node versions.
On a new Ubuntu system, first install the 'system' node:
curl -sL https://deb.nodesource.com/setup | sudo bash -
Then install n module globally:
npm install -g n
Since the system node was installed first (above), the alternatives system can be used to cleanly point to the node provided by n. First make sure the alternatives system has nothing for node:
update-alternatives --remove-all node
Then add the node provided by n:
update-alternatives --install /usr/bin/node node /usr/local/bin/node 1
Next add node provided by the system (the one that was installed with curl):
update-alternatives --install /usr/bin/node node /usr/bin/nodejs 2
Now select the node provided by n using the interactive menu (select /usr/local/bin/node from the menu presented by the following command):
update-alternatives --config node
Finally, since /usr/local/bin usually has a higher precedence in PATH than /usr/bin, the following alias must be created (enter in your .bashrc or .zshrc) if the alternatives system node is to be effective; otherwise the node installed with n in /usr/local/bin takes always precedence:
alias node='/usr/bin/node'
Now you can easily switch between node versions with n <desired node version number>.
On Linux Mint 17, I tried both solutions (creating a symlink or using the nodejs-legacy package) without success.
The only thing that finally worked for me was using the ppa from Chris Lea:
sudo apt-get purge node-*
sudo apt-get autoremove
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
This installed node version 10.37 and npm 1.4.28. After that, I could install packages globally.
As other folks already mention, I will suggest not to use "sudo apt-get" to install node or any development library. You can download required version from https://nodejs.org/dist/v6.9.2/ and setup you own environment.
I will recommend tools like nvm and n, to manage you node version. It is very convenient to switch and work with these modules.
https://github.com/creationix/nvm
https://github.com/tj/n
Or write basic bash to download zip/tar, extract move folder and create a soft link. Whenever you need to update, just point the old soft link to new downloaded version.
Like I have created for my own, you can refer:
https://github.com/deepakshrma/NodeJs-4.0-Reference-Guide/blob/master/nodejs-installer.sh
#Go to home
cd ~
#run command
#New Script
wget https://raw.githubusercontent.com/deepakshrma/NodeJs-4.0-Reference-Guide/master/nodejs-installer.sh
bash nodejs-installer.sh -v lts
#here -v or --version can be sepecific to 0.10.37 or it could be latest/lts
#Examples
bash nodejs-installer.sh -v lts
bash nodejs-installer.sh -v latest
bash nodejs-installer.sh -v 4.4.2
Simple solution from here
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash --
sudo apt-get install nodejs
You can specify version by changing setup_x.x value, for example to setup_5.x
Your System is not able to detect the path node js binary.
1.which node
2.Then soft link node to nodejs
ln -s [the path of nodejs] /usr/bin/node
I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.
Uninstall whatever node version you have
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs
install nvm (Node Version Manager) https://github.com/creationix/nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Now you can install whatever version of node you want and switch between the versions.
I fixed it unlinking /usr/sbin/node (which is linked to ax25-node package), then I have create a link to nodejs using this on command line
sudo ln -s /usr/bin/nodejs /usr/bin/node
Because package such as karma doesn't work with nodejs name, however changing the first line of karma script from node to nodejs, but I prefer resolve this issue once and for all
For me the fix was removing the node* packages and also the npm packages.
Then a fresh install as:
sudo apt-get install autoclean
sudo apt-get install nodejs-legacy
npm install
Problem is not in installer
replace nodejs with node or change the path from /usr/bin/nodejs to /usr/bin/node
This is the your node is not properly install, first you need to uninstall the node then install again.
To install the node this may help you
http://array151.com/blog/nodejs-tutorial-and-set-up/
after that you can install the packages easily. To install the packages this may help you
http://array151.com/blog/npm-node-package-manager/
you can create a link ln -s nodejs node in /usr/bin
hope this solves your problem.
node -v // first check it's install or not
npm -v
sudo apt install npm
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
sudo apt-get install nodejs
then check
node -v or node –version
npm -v or npm –version
or you can remove package.lock json file / node_modules than run npm i
I hope it'll work fine
steps : https://www.geeksforgeeks.org/installation-of-node-js-on-linux/
Faced same issue, steps below worked for me.
Install curl on your system then run NVM installer script.
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Load the environment
source ~/.profile
Install the supported version of Node.js.
nvm install 16.15.1
Confirm the installation
node -v

Resources