I see the following message when running the npm install
or npm
command from the terminal. Executing node
works as expected.
> npm install
/usr/bin/env: ‘bash\r’: No such file or directory
Run npm root -g to see the location, which varies. A common path is /usr/local/lib/node_modules.
Adding execute permissions to the "start" script. Removing all node modules, reinstalling node, re-creating the project file. Editing package. json to include the start script.
There are two main ways you can install Node. js and npm on Ubuntu: Using Ubuntu's official repository: Easy to install using apt but might have an older version. Using NodeSource repository: Slightly more complicated but you can choose which version to install, including the latest release of Node.
@treckstar When you install npm, the npm path will be added to .bashrc. And when you close and open the wsl terminal again, the .bashrc file wont run. So you use the command to run the file. It's possible that npm has been installed in the wrong place (e.g., in Windows rather than Ubuntu). To check, try running which npm.
The installation is pretty straightforward. Run the following commands to update the package index and install Node.js and npm: sudo apt update sudo apt install nodejs npm. The command above will install a number of packages, including the tools necessary to compile and install native addons from npm.
Hangs on "installing" with no errors. That command needs a parameter, it would look like wsl.exe --install -d Ubuntu. Before you do that, do: If either of those fail or hang, please collect WSL logs and post the backlink to the feedback item here.
We’ll install Node.js version 14.x: Run the following command as a user with sudo privileges to download and execute the NodeSource installation script: The script will add the NodeSource signing key to your system, create an apt repository file, install all necessary packages, and refresh the apt cache.
This may be a line endings issue, but not from Ubuntu. Make sure you have node
and npm
installed correctly:
sudo apt install nodejs npm
to install node & npmwsl --shutdown
to restart the WSL servicewhich npm
to confirm it's installed [output: /usr/bin/npm]Does the problem persist? Try this next:
Stop Windows path variables being shared with WSL by editing the /etc/wsl.conf
file in WSL. If the file doesn't exist, execute sudo touch /etc/wsl.conf
first. Edit the file with the command sudo nano /etc/wsl.conf
and add the following configuration:
[interop]
appendWindowsPath = false
Then restart WSL2 with command wsl --shutdown
in Windows.
Note 1: This will stop the PATH environment variables from Windows passing through to WSL. Known bug: this stops the VSCode code .
command from working in WSL. If this is a problem, use NVM solution described here or switch to using node in a docker container.
Note 2: this also affects pyenv
command, see /usr/bin/env: ‘bash\r’: No such file or directory: Incompatible line-endings (WSL?)
Tip from @mike: "I did not want to disable the ability to do code .
so I just removed the windows nodejs path by adding this line to my ~/.bashrc PATH=$(echo "$PATH" | sed -e 's%:/mnt/c/Program Files/nodejs%%')"
I hit the same issue, after install nodejs and npm, just restart my wsl with wsl --shutdown
solved the issue, you can try this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With