Installing Node.js - No such file or direktory - node.js

I have removed node.js on my CentOS. After that I was installing a new version node.js. Now I can't run the node.js:
-bash: /usr/local/bin/node: No such file or direktory
The only solution is to create a link
ln -s /usr/bin/node /usr/local/bin/node
Does anyone know why?

Recommend you to use nvm, very simple and can avoid many problems.
step one:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
step two:
nvm install stable
Check if successful:
node -v

I have solution for my problem. After re-login, everything is fine. I think the problem was somewhere in the ENV setup and reloaded after new login.

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.

env: node: No such file or directory in mac

I'm searching it in google on how to show the version of node js or how I'm gonna work with npm?
If I do this
npm -v
even I already install it using brew install node. The result is always
env: node: No such file or directory
I already do a lot of command to solve for it, but failed.
these are the command that I already try:
sudo apt-get install nodejs-legacy
sudo ln -s /usr/local/bin/node /usr/bin/node
brew unlink node
brew link node
I can't start the task because of this. help me guys. This work before after I used this command brew link --overwrite node. Now I have problem, i cant work anymore with npm. I'm really new about this. I don't have any idea now on how to fix this.
Update
I already get the list using npm list command. I also get the idea here link but when I npm install inside the project. I alwayst get this "result env: node: No such file or directory",even I command npm -v but If i command it outside my project. It work the npm -v
I solved it this way:
$ brew uninstall --force node
$ brew uninstall --force npm
after it
$ brew install node
which suggested me to overwrite simlinks
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/node/gdbinit
Target /usr/local/share/doc/node/gdbinit
already exists. You may want to remove it:
rm '/usr/local/share/doc/node/gdbinit'
To force the link and overwrite all conflicting files:
brew link --overwrite node
after executing
$ brew link --overwrite node
everything worked again.
NOTE: Only mac users!
uninstall node completely with the commands
curl -ksO https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh
chmod +x ./uninstall-node.sh
./uninstall-node.sh
rm uninstall-node.sh
Or you could check out this website: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
if this doesn't work, you need to remove node via control panel or any other method. As long as it gets removed.
Install node via this website: https://nodejs.org/en/download/
If you use nvm, you can use:
nvm install node
You can already check if it works, then you don't need to take the following steps with: npm -v and then node -v
if you have nvm installed:
command -v nvm
Uninstall npm using the following command:
sudo npm uninstall npm -g
Or, if that fails, get the npm source code, and do:
sudo make uninstall
If you have nvm installed, then use: nvm uninstall npm
Install npm using the following command: npm install -g grunt
I was getting this env: node: No such file or directory error when running the job through Jenkins.
What I did to fix it - added export PATH="$PATH:"/usr/local/bin/ at the beginning of the script that Jenkins job executes.
If you're switching from bash to oh my zsh, you will need to add nvm's path into the zshrc file.
#Zgpeace's answer here helped solve my issue (on IOS):
Open the .zshrc file. I used nano: nano ~/.zshrc
Add this into the file: export NVM_DIR=~/.nvm
Save changes by typing Ctrl+X --> Yes.
Reload the configuration. Type source $(brew --prefix nvm)/nvm.sh
Test by typing nvm --version.
You'll now be able to see the version. For e.g: 0.37.2
Thanks to this forum.
Sharing my notes below.
macOS Monterey
version 12.2.1
Chip Apple M1
$ brew uninstall --force node
$ brew uninstall --force npm
$ brew install node
$ brew link --overwrite node
$ brew doctor
$ brew cleanup
$ nvm --version
// 0.35.3
$ nvm use stable
// Now using node v17.6.0 (npm v8.5.1)
$ node -v
// v17.6.0
$ npm -v
// 8.5.1
I got such a problem after I upgraded my node version with brew. To fix the problem
1)run $brew doctor to check out if it is successfully installed or not
2) In case you missed clearing any node-related file before, such error log might pop up:
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built.
node
3) Now you are recommended to run brew link command to delete the original node-related files and overwrite new files - $ brew link node.
And that's it - everything works again !!!
It was nvm changing paths for me, this fixed it:
nvm use stable
I re-installed node through this link and it fixed it.
I think the issue was that I somehow got node to be in my /usr/bin instead of /usr/local/bin.
Let's see, I sorted that on a different way. in my case I had as path something like ~/.local/bin which seems that it is not the way it wants.
Try to use the full path, like /Users/tobias/.local/bin, I mean, change the PATH variable from ~/.local/bin to /Users/tobias/.local/bin or $HOME/.local/bin .
Now it works. 🙀🙀🙀
I get this error running npm start through PyCharm on Mac. For that the answer is to start PyCharm from the Terminal with open -a '/Applications/PyCharm.app/'. See https://stackoverflow.com/a/34017083/733092.
For Pycharm Professional, starting from the command line is different. Get the JetBrains Toolbox app, go to Settings, Generate Shell Script, and it will create a ~/pycharm_shell_scripts for you to run.
Working on MacOSx, maven exec not willing to execute a shell script that I could manually execute with desired result. Gave me the same error, solved it as well with
export PATH="$PATH:"/usr/local/bin/ at the beginning of the script
For mac user using the package manager homebrew:
-brew uninstall node
-brew uninstall npm
-brew doctor
-brew link node
-node -v (to check node version)
That's all you need.
For me, this error occurred when I tried to install a package with sudo npm. This fixed it:
sudo env PATH="$PATH:/usr/local/bin/" npm <rest of command>
I was using fish shell and encountered this problem on my m1 macbook air.
install nvm omf install nvm
add nvm to path by creating this file ~/.config/fish/functions/nvm.fish
I use vim so vim ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
install node again nvm install node
It worked for me after that, :) hopefully it does for you too
credit https://eshlox.net/2019/01/27/how-to-use-nvm-with-fish-shell
If you just installed/modified node and if intellij/webstorm or your shell is throwing this error, it's because it has not sourced the environment variables, try restarting the IDE/shell.
I also face this issue on mac. I had installed node using brew. I was able to resolve the issue by following these steps:
uninstall node using the command: brew uninstall --force node
uninstall npm using the command: brew uninstall --force npm
Then install node using the installer provided on the following link: https://nodejs.org/en/download/
Just did an update on my Mac OS which switched my .bash to /zshrc. Here is what I added to my ~/.zshrc file:
export NVM_DIR="/Users/< my name >/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # this loads nvm
Then I did a $ source ~/.zshrc and it refreshed those values.
Double checked my work with nvm --version and it was all good.
just run cmd:
% npm
before
% npx install-peerdeps --dev eslint-config-airbnb
on Mac m1 pro
Kept getting this error, found it it's because NVM wasn't using any version of node. I didn't set this but after using these commands it seemed to fix the error
nvm install lts/*
nvm use lts/*

Cannot run NPM Commands

I've been using NPM on my machine (Windows 10), but recently ran into an issue. I currently have Node.js installed and get the following error while running any npm command.
Question: What is causing this error and whats the best way to resolve it.
Command:
$ npm install
Output/Error:
bash: /c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory
Not my solution, but this seemed to work for me. Appears that having the Windows folder structure in $PATH while using WSL2 was causing that parse error, but I'm not exactly sure why.
Go to your user root (cd ~)
Open .bashrc in your chosen editor (vi, nano, etc.)
Append to the end of the file: export PATH=$(echo "$PATH" | sed -e 's/:\/mnt[^:]*//g') # strip out problematic Windows %PATH%
Close and re-open all terminal windows
Source: https://hackmd.io/#badging/wsl2#Troubleshooting-PATH
Updated: Per Lh Lee's comment, I've updated the regex from s/:\/mnt.*//g to s/:\/mnt[^:]*//g as this avoids accidentally capturing anything extra after the problematic /mnt paths.
Whereas the first regex will match /mnt/c/blah:/other/thing, the new one will not.
Install nodejs/npm using nvm and it will not conflict with the one in windows.
The path for npm becomes (after installing using nvm) /home/ubuntu/.nvm/versions/node/v14.16.0/bin/npm
Read More about setting up your Node.js development environment with WSL 2
I did with these commands.
sudo apt update && sudo apt install curl -y
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
nvm ls-remote
nvm install v15
node --version
This command with 78 upvotes:
# export PATH=$(echo "$PATH" | sed -e 's/:\/mnt[^:]*//g') # strip out problematic Windows %PATH%
causes problems with other commands such as the "code" command for VS Code. It manipulates the $PATH. The correct solution here is to use nvm:
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm ls
nvm use 14
I had the same issue, I solved it by installing my dependencies on my Linux sub system as well. In my case it was just nodejs and npm.
Open Ubuntu terminal(Windows Sub system) I'm on windows 10...
sudo apt update
Now that the system is up to speed, let's do...
sudo apt install nodejs npm
(Do a variation of this suitable to you, I assume most are using nodejs though.)
My npm works now but still gives the error first. I mean it's not aesthetic at first, but my terminal on VS Code doesn't have the error first. Which is awesome!
TLDR: The linux subsystem doesn't have npm so download it there first.
Edit: formatting
It happened to me just now and all I had to do was exiting my wsl2 session and login in again.
Just faced the same issue, this issue happens because npm is installed on your windows machine but not on your WSL one. you just need to install npm on your linux machine then it will read the binary from linux not windows that's in case you want to use windows paths on your WSL. otherwise if you don't need the windows paths you can use thing adam mentioned by adding this into your path: PATH=$(echo "$PATH" | sed -e 's/:\/mnt.*//g') then refresh the shell with source ~/.bashrc
I encountered the same problem and found the cause and a simple solution.
After installing nvm in bash a few months ago, I recently decided to give zsh and on-my-zsh a try. I followed the instructions and installed zsh and oh-my-zsh. When trying to run node or npm I got the errror:
zsh: /mnt/c/Program Files/nodejs/npm: bad interpreter: /bin/sh^M: no such file or directory
My investigations led me to the $PATH variable. I then compared the output of echo $PATH in bash and zsh. In bash the path included the nvm directory, in zsh this directory was not added to the path.
The reason for this difference is that nvm adds a snippet to the end of .bashrc. In zsh .zshrc is loaded instead and the snippet will not be executed.
The snippet looks like this:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
You can just copy these lines from .bashrc to the end of .zshrc, restart the shell, and the issue should be fixed if you have the same problem.
If you already installed everything you need following this link https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
just try restarting your VS Code and trying to run npm install.
I got this error when running npm install in a Visual Studio Code terminal, using Powershell. I switched to use a WSL2 terminal inside Visual Studio Code instead and it worked (tip - use npm i as a shorthand)
I am using Git Bash for cli
I my case my Antivirus has quarantined the C:\Program Files\Git\user\bin\sh.exe file, and that is why $ npm init was not working and showing this error:
bash: /c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory
When I restored that file it started working normally.
experienced this problem on my wsl2
not a fix but a workaround. unmounting the c drive resolve the issue.
umount /mnt/c
I had the same problem when I started using WSL, I solved it by using npm.cmd instead of npm command.

node -bash: /usr/sbin/node: No such file or directory

I am having this error with node. Running Debian 7 (Wheezy) a VPS.
I have this error if I for example run this command (in the directory of the .js)
node sell.js
or
screen node sell.js
They both don't work, because I am getting this error:
-bash: /usr/sbin/node: No such file or directory
Can somebody help me?
As in #Quentin's answer, the name of the executable may be incorrect. In many cases, what got installed was nodejs, not node. The line below creates a symbolic link that points to nodejs from where your system looks when you type node. It is a work-around - an alternative to simply typing nodejs
sudo ln -s /usr/bin/nodejs /usr/sbin/node
The Debian package for NodeJS is called nodejs and installed the executable /usr/bin/nodejs.
node is the wrong program, it is for ham radio operations, and your install of it appears to be broken anyway).
I ran the command:
sudo apt-get install nodejs-legacy
and nodejs worked again!
Maybe something wrong happened during your node's installing.
And system environment variable shows the command "node" referes to /usr/sbin/node .
Try download node linux binaries from official. Rename and put it in /usr/sbin after extracting the source. Of course you can put it in another folder as long as you update the system environment variables.

nodejs is already the newest version but "node -v" doesn't give a response

This is really confusing me. If I type "node -v" into the command line, there is no response - it just gives me the $ prompt again. Trying to install node with sudo npm install nodejs gives the response nodejs is already the newest version.
How can I debug this to find out what's going on?
nodejs -v solved the problem.
In some linux distributions node executable is mapped into nodejs.
Are you trying to print the node version? If yes then try
$ node --version
Node is by default installed on /usr/bin/ directory on linux OS it means it should run with normal user privilege but node include some tools that required Superuser privilege so ...
Instead running
node -v
run
sudo node -v
hope it will work...keep coding

Resources