npm install error `not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:` - npm-install

I have installed Ubuntu Bash on Windows. I already have nodejs and npm on my windows machine at C:\Program Files\nodejs. In the bash shell in Windows, I am running a script which uses npm install command. The script is giving following error
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

Note: Before following the steps below, first try to restart your shell.
You can install Node.js and NPM with your Windows PowerShell as well, so if you've done that it won't work properly for your Subsystem. That means you have to install it twice (Powershell and Subsystem) or decide on one thing.
If the preceding text, has not helped you, this is how to solve the problem:
Remove your current installations
sudo apt-get --purge remove node
("sudo apt autoremove node" if console is asking for it)
sudo apt-get --purge remove nodejs
Install node the right way.
This is for version 14 (view current LTS version):
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Then install build tools so you can install add-ons for npm later
sudo apt-get install -y build-essential
Now you can type in
npm -v
node -v
Same thing: nodejs -v
to check whether Node.js and NPM are installed correctly. If it shows nothing, restart the shell.
If it still shows the same error, restart the WSL/ PC or try with sudo npm -v
Here are two links that may also help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
https://github.com/nodesource/distributions/blob/master/README.md#debinstall
Also, take a look at the Node Version Manager (NVM). With it, you can easily switch back and forth between versions.

The solution provided by phucanhapril on May 24, 2017 in this thread worked for me.
To summarise, edit ~/.profile and change your PATH to this:
PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"
(By default it does not include /usr/bin)
Then run:
source ~/.profile
I am not quite sure why npm doesn't work properly in the first place, or why /usr/bin isn't in PATH by default, but the solution worked for me.

I had the same problem to solve I installed "NVM" in my Subsystem
Follow these steps and see if it will solve for you:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm install 11.13.0

You can try sudo npm install it was a solution in my particular case.

Linux command for install nodejs and npm
sudo apt-get install nodejs
sudo apt-get install npm
Set path in linux
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
reference
https://github.com/microsoft/WSL/issues/3882

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
this is enough, if you still face the problem
node installation needs restart, close you ubuntu window and start again it will solve your problem :)

I had the same problem. This is what I did.
Step 1. Type node -v and npm -v commands in Windows PowerShell and check if node and npm are properly installed
Step 2. Add this to the ~/.zshrc or ~/.bashrc file
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Step 3. Type source ~/.zshrc and/or source ~/.bashrc
Step 4. Type node -v and npm -v commands in bash or zsh shells and the correct versions should now appear

On Visual Studio -> Tools -> Options -> Projects and Solutions -> Web Package Management -> make sure $(PATH) is above all the rest.
As long it is not located at the top of the list VS will try to use VS tools instead of npm.
You should also refer windows to the current npm version by following this screenshot, after try npm --version.
Changing npm path:

I had this issue in both Debian and Ubuntu (though in Ubuntu the nvm command did work) when I was running Windows 10 version 1703. Then when I upgraded to version 1903 the problem disappeared.

I had the same error and it may seem silly, but I fixed it by simply typing exit in the console and opening it again.

I received this error when I modified my "~/.bashrc" file to shorten up the bash directory.
At first I had:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\$'
fi
....But then could not run any node operation. I rolled it back and the error stopped happening.
After some troubleshooting, I was able to fix the error by adding ~ before the $ on PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\~$

I just read through many threads trying to do this. There is complete documentation for setting up node, nvm, and npm in wsl, here: https://learn.microsoft.com/en-us/windows/nodejs/setup-on-wsl2
If you already installed node and npm using the following commands,
sudo apt-get install nodejs
sudo apt-get install npm
NPM will not work. You must first uninstall them using:
sudo apt-get remove nodejs
sudo apt-get remove npm
Follow the guide to completely uninstalling here: How can I completely uninstall nodejs, npm and node in Ubuntu
Then reinstall from the windows guide referenced above.
The windows guide has many other useful resources.
The Tldr to install(from Microsoft Docs):
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts

I had identical output to that in the question. It occurs because Ubuntu on WSL adds Windows paths to the bash shell, but of course the Windows executables do not work in bash.
I installed nvm, and from there installed node into bash. NVM works out all the paths so it works.

Related

how to correctly install wkhtmltopdf in linux mint?

IM trying to install "wkhtmltopdf"
sudo apt install ./wkhtmltox_0.12.6-1.bionic_amd64.deb
when I try to run I get this command
E: Unsupported file ./wkhtmltox_0.12.6-1.bionic_amd64.deb given on commandline
can anyone show me how to fix this?
Use
# sudo dpkg -i wkhtmltox_0.12.6-1.bionic_amd64.deb
# sudo apt install -f
The last command should install any missing dependencies when running the first command.

Install yarn and npm in WSL

I have installed Windows Subsystem for Linux (WSL) and Ubuntu 16.04 on my Windows 10. Then I followed this to install yarn:
sudo apt update
sudo apt install curl
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn
It did not raise any error. However, yarn --version returned
$ yarn --version
/mnt/c/Users/chengtie/AppData/Roaming/npm/yarn: 12: /mnt/c/Users/chengtie/AppData/Roaming/npm/yarn: node: not found
npm --version returned
$ npm --version
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
Does anyone know how to fix this?
Look at this:
/mnt/c/Users/chengtie/AppData/Roaming/npm/yarn: 12
It is looking for the yarn installed on Windows. You must or uninstall yarn from windows or remove it from the WSL's PATH.
Use the following to remove windows yarn from the PATH:
WIN_YARN_PATH="\$(dirname "\$(which yarn)")"
export PATH=\$(echo "\${PATH}" | sed -e "s#\${WIN_YARN_PATH}##")
You can add this to your .bashrc
Also, look at your error messages it is getting also npm from windows, you need to remove them from the path using the same technique.
You need to type:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
then:
sudo apt-get install -y nodejs
You must install nodejs before
sudo apt-get install nodejs
If you have latest nodejs version installed:
I encountered the same issue and it got fixed by trying sudo npm -v and to get npm without sudo, I restarted the WSL.
If you don't have the latest nodejs version:
If you are on WSL, you can install the Latest stable version by
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
In place of setup_8.x you can keep setup_16.x for version 16 (which includes npm).
sudo apt-get install nodejs
check nodejs version by nodejs -v.
check npm version by npm -v.
If still the same error codes. try sudo npm -v or restart PC/ WSL then try npm -v.

How to install PhantomJS on vps?

I tried to use pip install, but it tells cannot find such package.
I also see someone say we can use brew and nodejs to install. This is what I tried to install brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It returns that ruby doesn't found.
I have no idea about nodejs.
Anyone knows how can I install PhantomJS in the server?
Meet npm!
Npm stands for Node Package Manager.
You can install packages for using them from the CLI or from your nodejs app.
You can install NPM from here.
If node isn't installed yet, you can use NVM, which makes it really easy -
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
For your question,
See this specific package.
You can install it via:
$ npm install phantomjs-prebuilt
And then you should be able to: $ bin/phantomjs [phantom arguments] to run phantomJS from the terminal.
PhantomJS is a standalone application with its own website which has binaries for all major platforms and documentation. You don't really need pip or npm or bundler to install it, just do it manually.
Go to http://phantomjs.org/download.html
Choose the appropriate binary (Linux x32 x64 / OSX / Windows), download archive, extract it and run the binary.
For example you have a x64 Linux distribution.
Log in to your server via ssh.
Go to your home directory:
cd ~
Download PhantomJS binary:
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
Extract archive:
tar xvf phantomjs-2.1.1-linux-x86_64.tar.bz2
A new directory is created: phantomjs-2.1.1-linux-x86_64. The PhantomJS binary is phantomjs-2.1.1-linux-x86_64/bin/phantomjs. You can run it right now:
~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs --version
2.1.1
(If it says "not found " instead that means you chose the wrong distribution, e.g. x64 instead of x32).
But this way of running it is inconvenient. It would be way better to be able to just type phantomjs script.js in any directory. To make it so add a link to a directory where binaries are kept by default:
sudo ln -s ~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
Then you can call PhantomJS from anywhere:
cd /var/www/
phantomjs --version
2.1.1

Is NVM working on latest Windows Linux Subsystem (WSL)?

I'm able to install NVM via script and able to execute something like nvm use v6.3.1
However everytime I try to install stuff from my package.json i get permission denied errors as described here
https://github.com/Microsoft/BashOnWindows/issues/14
I tried looking online but no clear answers. Is nvm working on the latest WSL?
Is npm working ok for you?
Not sure if you error is related, but I found I had to either:
sudo apt-get install nodejs-legacy
or
sudo ln -fs /usr/bin/nodejs /usr/local/bin/node
in order to get Node to work properly.

npm module n emits errors

After installing n by command 'sudo npm install -g n',
I want list all node versions,but some errors come out, even though, n can work normally!
As bellow:
$ n list
/usr/bin/n: line 262: which: command not found
/usr/bin/n: line 262: which: command not found
0.0.1
0.0.2
0.0.3
0.0.4
I don't know why, there is no need to configure my bin foldeer.
I have solved it, after npm install which...
sudo npm install -g whitch
Try installing which
sudo apt-get install which
This is fixed in the current version of n.
Old versions of n used the which command which is not standard. Newer versions only use command -v which is a standard posix command.