Installed Node.js but File Cannot be Found by Command Prompt - node.js

I installed node.js onto my Raspberry Pi, which is running on Raspbian Stretch.
To install, I used the command $ sudo apt-get install -y nodejs. There were no problems with installation.
When I try to test the installation by typing $ nodejs -v into the command prompt, it returns
nodejs: command not found
If I try to install it again, the prompt returns
nodejs is already the newest version (8.11.1~dfsg-2~bpo9+1)
Also, when I look into my /usr/bin folder, I see that node.js is there.
I've spent a while searching for what could be causing this issue to no avail. I think maybe the node.js file is in the wrong folder, but none of the tutorials I've read has a step where you would move the file.
Any help to get node.js to work would be greatly appreciated! :)

Try this:
Step 1: This command updates our Debian apt package repository to include the NodeSource packages.
$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Step 2: Install NodeJS (THis will ensure you are installing latest version)
sudo apt install -y nodejs
Step 3: Enjoy NODEJS in RaspberryPi
$ node -v
v10.6.0
$ node
> 1 + 3
4
> # We can hit Ctrl-C twice to exit the REPL and get back to the bash (shell) prompt.
If you are having conflicts with previous NODE installations, do this to remove all existing installations:
Running which node will return something like /path/bin/node
Then run cd /path
Then run rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Hope it helps!

Related

How To Make Node Server Always Load Within Service

I have a simple service file that is supposed to run a bash script that starts a node js server in my "build" directory.
Contents of the script are
#!/bin/bash
cd /home/path/to/build && npm install -g serve && serve -l 5679
However, I get the error => /usr/bin/env: ‘node’: No such file or directory
Even when I try a symlink like so
#!/bin/bash
cd /home/path/to/build && ln -s /usr/bin/nodejs /usr/bin/node && npm install -g serve && serve -l 5679
I get the error => failed to create symbolic link ‘/usr/bin/node’: File exists
Please how do I fix this? I wouldn't want my user to have to manually start serving on each reboot. It also works if I add the script contents straight to terminal.
Thanks for any help!
Turns out I had to install node with a different method (inspired by https://www.geeksforgeeks.org/installation-of-node-js-on-linux/) to ensure it actually existed in /usr/bin because ExecStart didn't like having the "serve" command working with my symlink node.
Step 1: Open your terminal or press Ctrl + Alt + T and use the following commands to update and upgrade the package manager:
sudo apt-get update
sudo apt-get upgrade
Step 2: Install Python software libraries using the following command:
sudo apt-get install software-properties-common
Step 3: Add Node.js PPA to the system.
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Note: Here, we are installing node.js version 14, if you want to install version 11, you can replace setup_14.x with setup_11.x.
Step 4: To Install Node.js and NPM to your Ubuntu machine, use the command given below:
sudo apt-get install nodejs
Step 5: Once installed, verify it by checking the installed version using the following command:
node -v or node –version
npm -v or npm –version

Rookie error with Node.js, Johnny Five and Raspbian

I'm currently trying to communicate with Arduino through a web server created with Node.js installed on my Orange PI PC. In order to do this, I tried to use the module called johnny five, but the only output I receive is a bunch of errors.
I'm using Raspbian v0.8.0 for Orange PI PC.
I installed node v0.10.0 by using wget plus the link.
Then, I unpacked the file by using:
cd /usr/local
sudo tar xzvf ~/node-v0.10.0-linux-arm-pi.tar.gz --strip=1
The version of node is 0.10.0 and the NPM's version is 1.2.14. When I tried to update the npm with the command npm install npm -g
these errors came in
Then, I tried to install johnny-five by following the guide that I've found on the johnny-five website which is linked to Github
And this happened
If I try to run a program, many error appear saying at the top of them 'cannot find module johnny five'.
This version of node is the only one that works for me after checking many other of them.
Try and set up a more advanced version of node.js. I had success with node v4. This will update NPM/Node.
# install updates
sudo apt-get update && sudo apt-get upgrade
# install node
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
# test
node -v
npm -v
# clone the code of the project in a folder and continue normally
You can find an old version in the Heroku web:
https://node-arm.herokuapp.com/
But if you want a more recent go to https://nodejs.org/en/download/ and dowload a new one from Linux Binaries (ARM). Unzip the binary archive to any directory you wanna install Node, I use /usr/lib/nodejs:
sudo mkdir /usr/lib/nodejs
sudo tar -xJvf node-v8.9.4-linux-armv7l.tar.xz -C /usr/lib/nodejs
sudo mv /usr/lib/nodejs/node-v8.9.4-linux-armv7l /usr/lib/nodejs/node-v8.9.4
Set the environment variable ~/.profile, adding below to the end:
# Nodejs
export NODEJS_HOME=/usr/lib/nodejs/node-v8.9.4
export PATH=$NODEJS_HOME/bin:$PATH
Refresh profile:
.~/.profile
Test installation using:
node -v
and
npm version

Installing nodejs via nvm fails

I spend a lot of time and tons pages...
I have a an strange issue while installing nodejs on ubuntu 14.04 server (via nvm). When i run "nvm install 0.12.7" nvm gives me an answer:
curl: (6) Could not resolve host: nodejs.org
grep: /root/.nvm/bin/node-v0.12.7-linux-x86/node-v0.12.7-linux-x86.tar.gz: No such file or folder
Binary download failed, trying source.
nvm: install v0.12.7 failed!
If i type "nvm install 0.12.7" one more time, i got answer message:
Version '0.12.7' - not found - try 'nvm ls-remote' to browser available versions
I was try to install all available versions, also with -s postfix, but has a same error. I was try to install nodejs with sudo & from root. Same error. I was try uninstall and reinstall nvm with sudo and from root. Same error.
If i re-login and type nvm instal..... - I'll get a first fail, then second and so on.
I can install nodejs using apt-get, but i need to use nvm, it must be able to test project on many nodejs versus installed. Hope for help!
I also had the same issue on ubuntu 14.04. Simply append v in front of version. That is the command will be nvm install v0.12.7.
And it worked like charm for me!
Instructions to Install Nodejs latest Version for Ubuntu via NVM:
P.s - In order to Unistall NVM:
rm -rf $NVM_DIR ~/.npm ~/.bower
Start With This:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Exit the Terminal and Start Again
nvm install 14.4.0 (or your preferable version)
3....
sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /etc/apt/sources.list.d/*
sudo apt-get update
4...
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
5...
sudo apt-get install -y nodejs
6..
sudo apt install build-essential
Manually adding the . ~/.nvm/nvm.sh (or bash ~/.nvm/nvm.sh) causes it to complain: N/A: version "N/A" is not yet installed. Even nvm list causes this error.
With me, it worked when I added versions directories manually 😕
mkdir ~/.nvm/versions
On that link https://github.com/nvm-sh/nvm/issues/2771 was exactly what happened to me. I just uninstalled the curl snap package and installed it again using apt and finally removed nvm and reinstalled it again, all following the instructions on their github repo https://github.com/nvm-sh/nvm#uninstalling--removal

Nodejs installed without npm?

I've just installed nodejs on Debian 7 - by apt-get install nodejs.
Nodejs seems to be working fine, but when I enter "npm" I get "command not found".
"which nodejs" points to "usr/bin" and there it is - nodejs, but there is no npm file, what went wrong?
I found a few solutions, but all of them are related to Macs
BTW, "usr/local/bin" directory is empty I believe everything should install right there?
You have several options.
If you want to continue using Debian packages, you could install npm (debian maintainers have it in a separate package).
apt-get install npm
If you want to just install npm, you can use this modification of Maxime's answer:
curl -L https://npmjs.org/install.sh | sudo sh
(the -L is needed to make curl follow redirects.)
Finally, you may wish to use a different package source.
For some Linux distributions (Debian/Ubuntu and RedHat/CentOS), the latest node version provided by the distribution may lag behind the stable version. Here are instructions from NodeSource on getting the latest node, which includes npm and avoids using the problematic nodejs alias
Install npm
curl -L https://npmjs.org/install.sh | sudo sh
(the -L is needed to make curl follow redirects.)
and check version
npm -v
Node.js is easy to install in Linux
create a directory nodejs inside /usr/local/lib
download nodejs
move downloaded tar.xz file inside /usr/local/lib
extract the tar.xz file and rename as like node-v8.9.4
setup environment
cd ./etc/profile.d
ls
sudo touch nodejs-env.sh
sudo atom nodejs-env.sh
where atom is my favourite editor; you can use your editor.
copy and paste below code inside nodejs-env.sh and save
export NODEJS_HOME=/usr/local/lib/nodejs/node-v8.9.4
export PATH=$NODEJS_HOME/bin:$PATH
restart you machine.
done
There were several methods to install node.js on your debian. But I prefer this one:
Setup with Debian (as root):
apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
Then install with Debian (as root):
apt-get install --yes nodejs
After that, relaunch your terminal and type "npm" in your terminal.
The problem you're facing is due the need of super user rights during the installation. As others mentioned, you could do it via the sudo command and the manual installer.
Either way, there're several ways to install node in *unix platforms in a safer way without the need of super user rights using NVM (Node Version Manager).
Steps:
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
$ nvm install 0.10
Also, you can find different techniques to install node and npm without having to sudo.

Installing NPM on AWS EC2

Working on Ec2 on AWS.
I have installed Node.js and it works fine.
But the problem arises when trying to install npm.
I am using the following command to install it:
sudo curl http://npmjs.org/install.sh | sh
But the install seems to freeze...
I get "fetching: http://registry.npmjs.org/npm/-/npm-1.0.106.tgz" at the prompt and it stays on like this.
Have any idea what is going on here?
sudo yum install nodejs npm --enablerepo=epel
Follow this AWS Tutorial that uses Node Version Manager.
Node Version Manager (NVM) lets you install multiple versions of Node.js and switch between them.
Here are the steps:
Install NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
Activate NVM
. ~/.nvm/nvm.sh
Install Node (choose version)
nvm install 15.0.0
Confirm Successful Installation
node -e "console.log('Running Node.js ' + process.version)"
To install NodeJS 6.x execute the following commands:
curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource
Update
You can install NodeJS 7 and 8 in the same way. Just specify the version you need instead of 6 in the command above.
Update
To update to NodeJS 16 (or any other version) do the following:
rm -rf /etc/yum.repos.d/nodesource-el*
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
yum install nodejs --enablerepo=nodesource
Simplest way to install npm/nodejs on Amazon Linux 2 ec2 isntance:
First install epel repo using amazon-linux-extras command as below:
sudo amazon-linux-extras install epel
Now install npm and nodejs as below:
sudo yum install nodejs npm
you can verify the version of node and npm as below:
node -v
npm -v
PS. I've tested this on Amazon Linux 2 AMI (HVM) ec2 instance.
This guide worked perfectly: https://tecadmin.net/install-latest-nodejs-amazon-linux/
Make sure you have make
# sudo yum install -y gcc-c++ make
Install source
# curl -sL https://rpm.nodesource.com/setup_14.x | sudo -E bash -
Install node
# sudo yum install -y nodejs
Note - you'll have to run sudo npm install to get the installs to work.
Firstly
sudo yum install make
You can run this to get zip of desired version of node
wget https://nodejs.org/dist/v8.10.0/node-v8.10.0.tar.gz
Then you can unzip it like this
tar -xvf node-v8.10.0.tar.gz
then go in to the extracted directory and install node like this
./configure && make && sudo make install
I found his tutorial that has been very usefull to me: The last chapter explains how to install node and npm compiling it.
http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/#installNode
Get the http://npmjs.org/install.sh file on your system first and then execute it directly instead of piping with curl.
Use chmod +x install.sh to make it executable
Then run ./install.sh
I did it manually. Why mess with installers that break or don't put things where I want them? Such were the problems encountered while installing *node.js" on Amazon Web Services, that a manual install was the easy way to get the result I wanted.
I want a GLOBAL install of node and npm on AWS. By that I mean install should be put in a place like /usr/bin, so that all users have access. Surprisingly, AWS apparently doesn't give support to that idea. AWS encourages using nvm, node version manager, but that seems to always install in a user directory, and not a system level directory. After being frustrated when the "rpm" solutions (mentioned elsewhere) failed, I finally decided to just do the installation manually.
In a browser, go to nodejs.org download page:
https://nodejs.org/en/download/
Find a link that says:
All download options
Click through that; it goes to an index page with a URL like:
https://nodejs.org/dist/v14.16.1/
There I looked for the name that had "linux" and "x86" in the name.
I wrote this down, or select-and-copied, to get the correct spelling.
In my case it was:
node-v14.16.1-linux-x64.tar.gz
Putting the two parts together, I got the following URL:
https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz
So that's what is to be downloaded using curl.
I have a "temp" directory conveniently located in my home dir.
cd ~/temp
The download was accomplished with "curl". Note that the -o option was used to give the output file the name of my choosing. Of course, I chose to give it the same name as the web site file.
curl -o node-v14.16.1-linux-x64.tar.gz https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.gz
Untar the downloaded file.
tar xf node-v14.16.1-linux-x64.tar.gz
Conveniently, it creates its own directory. Go there.
cd node-v14.16.1-linux-x64 || exit 1;
Observe that the delivery consists of a relatively small number of files and directories (since node_modules is dealt with as a unit).
In my case, I had an old and bad implementation still installed, so the following commands were used to move aside any junk that might happen to be in the way. Some commands errored out because the old junk didn't exist. That's ok, error while moving to -OLD just means there is nothing to move; which is good.
Note: I put all these mv (move) commands into a script file, made it executable, and ran it as sudo. The alternative is to run each line individually as sudo.
mv /usr/bin/node /usr/bin/node-OLD
mv /usr/bin/npm /usr/bin/npm-OLD
mv /usr/bin/npx /usr/bin/npx-OLD
mv /usr/include/node /usr/include/node-OLD
mv /usr/lib/node_modules /usr/lib/node_modules-OLD
mv /usr/share/doc/node /usr/share/doc/node-OLD
mv /usr/share/man/man1/node.1 /usr/share/man/man1/node.1-OLD
mv /usr/share/systemtap/tapset/node.stp /usr/share/systemtap/tapset/node.stp-OLD
An here is the actual install. Remember, this is occurring in the untarred directory, in my case node-v14.16.1-linux-x64.
mv bin/node /usr/bin
mv bin/npm /usr/bin
mv bin/npx /usr/bin
mv include/node /usr/include
mv lib/node_modules /usr/lib
mv share/doc/node /usr/share/doc
mv share/man/man1/node.1 /usr/share/man/man1
mv share/systemtap/tapset/node.stp /usr/share/systemtap/tapset/
That's it, all finished.
Latest version 18 has dependency I think..
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)
Finally I got solution by running by running following commands.
sudo apt-get remove nodejs
nvm install 16.15.1
v16.15.1 node version and npm v v16.15.1 is installed.
For same make sure nvm is installed in your machine.
This works for me:
sudo apt install npm
Edit as my answer wasn't pertinent anymore:
Try:
curl --silent --location https://rpm.nodesource.com/setup | bash -
yum -y install nodejs
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#enterprise-linux-and-fedora-core

Resources