Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After installing npm on WSL Ubuntu 20.04 I get the message "/usr/bin/env: ‘bash\r’: No such file or directory"

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
like image 566
Zymotik Avatar asked Jun 11 '21 14:06

Zymotik


People also ask

Where is npm installed on Ubuntu?

Run npm root -g to see the location, which varies. A common path is /usr/local/lib/node_modules.

How do I start npm in Ubuntu?

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.

How do I install npm on Ubuntu?

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.

Why can't I run NPM in WSL?

@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.

How do I install NPM on Ubuntu terminal?

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.

How to install Ubuntu with WSL without any errors?

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.

How do I install node source on Ubuntu?

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.


2 Answers

This may be a line endings issue, but not from Ubuntu. Make sure you have node and npm installed correctly:

  1. From WSL run sudo apt install nodejs npm to install node & npm
  2. From PowerShell/CMD run wsl --shutdown to restart the WSL service
  3. Next in WSL run which 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%%')"

like image 130
Zymotik Avatar answered Oct 13 '22 22:10

Zymotik


I hit the same issue, after install nodejs and npm, just restart my wsl with wsl --shutdown solved the issue, you can try this.

like image 8
fsarter Avatar answered Oct 13 '22 23:10

fsarter