`gulp` command doesn't work as expected on Linux - linux

I am trying to set up the needed environment for a project I am gonna work on. I am not able to run gulp command as expected (as it is told on the getting started page of Gulp).
I am using Linux (PopOS) which is based on Ubuntu and Debian.
So, I have tried to fix it in the local project repo - which was unsuccessful.
Then I decided to create a new project directory and see whether it works. I have done these in the new project file:
$ node -v
v8.10.0
$ npm -v
5.6.0
$ npx -v
9.7.1
$ npm install --global gulp-cli
$ npm install --save-dev gulp
After all these, at the last step, when I do:
$ gulp
-bash: /usr/bin/gulp: No such file or directory
this is what I get.
However, if I do this,
$ node_modules/gulp/bin/gulp.js --version
CLI version: 2.2.0
Local version: 4.0.2
I get some result.
Does anybody see why gulp isn't getting in my binary directory? - Even though I have done the same exact steps that are presented on the official website?

This issue was about npm prefix that defines the directory where npm packages will be installed. Because the gulp binary wasn't in one of the directories that is in PATH variable bash wasn't able to find it. Here you can find details about how to fix.

Related

npm commands not working on Bash on Ubuntu on Windows (WSL)

I am running latest stable windows with bash on Ubuntu running through cmder wslbridge (i tried running directly through bash but same errors). Moving to my windows based react-native folder and trying to run some cli like npm run android , react-native run-android , gradlew clean is always producing errors;
while surprisingly some other commands like npm start work properly...
which npm print out; /usr/local/bin/npm
i have npm installed on windows and inisde Ubuntu and whereis npm produce this
I am really confused here; when running npm commands inside the bash onto windows folders which npm should be triggered? the windows or WSL one?!
I've tried a lot of suggested solution, but nothing seems to be working...
As you have said you are unsure what is actaully running when you run the commands. if you run the following commands it might make it clear as to what is actually running.
➜ ~ whereis npm
npm: /usr/local/bin/npm /home/damo/.nvm/versions/node/v8.11.1/bin/npm /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd
➜ ~ which npm
/home/damo/.nvm/versions/node/v8.11.1/bin/npm
➜ ~ npm --version
6.4.1
➜ ~ sudo find / -name npm
/home/damo/.npm/10.52.63.39_4783/npm
/home/damo/.npm/npm
/home/damo/.nvm/versions/node/v10.4.1/bin/npm
/home/damo/.nvm/versions/node/v8.11.1/bin/npm
/home/damo/.oh-my-zsh/plugins/npm
/mnt/c/Program Files/nodejs/node_modules/npm
/mnt/c/Program Files/nodejs/node_modules/npm/bin/npm
/mnt/c/Program Files/nodejs/npm
/mnt/c/Users/stangerd/AppData/Roaming/npm
➜ ~ echo $PATH
/home/damo/.nvm/versions/node/v8.11.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/cmder/vendor/conemu-maximus5/ConEmu/Scripts:/mnt/c/Program Files/cmder/vendor/conemu-maximus5:/mnt/c/Program Files/cmder/vendor/conemu-maximus5/ConEmu:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/HashiCorp/Vagrant/bin:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/Beyond Compare 4:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/Microsoft VS Code/bin:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Users/ stangerd/AppData/Roaming/npm
➜ ~ nvm use 10
Now using node v10.4.1 (npm v6.1.0)
➜ ~ echo $PATH
/home/damo/.nvm/versions/node/v10.4.1/bin:/usr/local/sbin:/usr/local/bin:........
You can see that for me i also have many versions of npm, but that its my WSLs current nvm version that is being used (shown by running which npm). This is because when the path is searched the first one found will be used. the first instance of npm in all the folders in my path is in /home/damo/.nvm/versions/node/v8.11.1/bin. Notice that when using nvm the path will be changed when switching node versions and that conveniently it puts this new path on the front of all the existing path folders.
Its also worth checking the alias set as this gets evaluated before the path is even queried. Just run alias to get a list.
Hope that this helps to find what is actually running. I'm interested to hear how you get on.

A package I install using npm -g it doesn't show up in a bash script, why?

I have this post-receive script as a git hook when exporting with the following contents
#!/usr/bin/env bash
export NODE_ENV=production
git --work-tree=/home/myusername/app --git-dir=/home/myusername/git checkout -f
cd /home/myusername/app
npm prune
npm install --production
knex migrate:latest
When ssh'd in my server I installed knex globally but it doesn't seem to exist within the bash shell's environment. I lack the knowledge of knowing how they are different. I also noticed my node versions were different. How do I import my user's normal environment?
To get the names and versions of modules that you have installed globally run:
npm list --global --depth=0
You can then install those modules on the second system with:
npm install --global module_name module_name ...
If you want to install a specific version of Node on the second system you can use nvm or see those answers for details:
Run npm as superuser, it isn't a good idea?
node 5.5.0 already installed but node -v fetches with "v4.2.1" on OS X & homebrew?
Node installed but node cannot be found in Ubuntu VPS
This is the first time I see a shebang like that:
#!/usr/bin/env bash
I've seen using /usr/bin/env to find node, python, perl interpreters etc. but never for bash. Usually it's just:
#!/bin/bash
Remember that if you want to run some program from a Bash script (without giving a full path) then it must be in a directory that is in the PATH environment variable.
To see your PATH run:
echo $PATH
Or you can use a full path to a binary in a script:
#!/bin/sh
/full/path/to/something
and then it doesn't need to be in the PATH.

NPM not found when using NVM

I have installed node/npm using the nvm documentation.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
Then:
nvm install node
At this point node is working but the npm command result with:
npm: command not found
How can I have npm to work correctly ?
I found out that this was a conflict with a previous versions of npm that have not been removed properly despite a apt-get remove node.
I solved it by reinstalling npm from scratch:
rm -R ~/.npm ~/.nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm install node
I found the solution here.
If you run NVM-Windows, don't forget to run nvm on. (this solve the problem as title for me.)
I fixed this by doing this command:
$ command -v npm
and then reopen the shell window.
I solved it by uninstalling all problematic node versions (e.g. v14 below) and reinstalling it.
The problem:
node --version; npm --version;
v14.17.1
Command 'npm' not found, but can be installed with:
sudo apt install npm
The solution:
nvm deactivate
echo "All versions BEFORE:"
nvm_ls
# uninstall all 14.* versions
for v in $(nvm_ls 14); do nvm uninstall $v; done
echo "All versions AFTER:"
nvm_ls
# reinstall version 14
nvm install 14
# and now it has npm too
node --version; npm --version
which node; which npm
# v14.17.1
# 6.14.13
# /home/user/.nvm/versions/node/v14.17.1/bin/node
# /home/user/.nvm/versions/node/v14.17.1/bin/npm
If you use Windows OS, make sure you removed the existing nodejs and npm.
In my case, it worked well after I remove the C:/Program Files/nodejs.
Reference is here.
During nvm installation, make sure the selected path must NOT exist.
This problem especially happens in windows which happens because of missing admin rights for cmd.
If you are using Git bash
Go in installation directory e.g C:\Program Files\Git
Right click properties -> compatibility.
Tick the checkbox with label -> Run as administrator.
Run the git bash again & execute npm list and then npm use 'version_to_be_used'
Same goes for Cmd
One possible reason is the NVM symlink is invalid.
But first, check if both NVM_HOME & NVM_SYMLINK is already set in environment path.
If not, maybe some problem with your nvm installation and u might want to reinstall.
Using explorer, open the symlink folder to check if the folder is valid.Default Symlink path in Windows: C:\Program Files\nodejs. Symlink appears as a normal shortcut in Windows explorer.
If you see node files in there, then you're fine.
If the folder is invalid, delete the symlink.
Then, execute nvm ls and nvm use <desired node version>, this step will re-create the correct symlink.
Restart CMD and test nvm current, node -v, npm -v
For Windows:
nvm creating symlink from installed node path like c:\program files\node to the c:\users<your user>\AppData\nvm<node ver>
So check:
Your basic node path in the PATH variable.
Your npm is inside c:\users<your user>\AppData\nvm<node ver>\nmp and this path is also int the PATH variable.
You could also run
source ~/.bashrc
and try to run again on the same bash terminal where you downloaded the install.sh the command:
npm -v
I went through a similar issue recently and solved it by setting the npm mirror to npm_mirror https://github.com/npm/cli/archive/refs/tags/
The default npm mirror (https://github.com/npm/cli/archive) was a broken link.
so run
nvm npm_mirror https://github.com/npm/cli/archive/refs/tags/
I had the same issue while any new terminal instance started up the message 'npm not found' was shown. I noticed that I had defined (probably) custom paths to npm and node in ~/.bashrc. Deleting them (keeping the paths for nvm) resolved the problem.
This helped me: https://github.com/coreybutler/nvm-windows/issues/548#issuecomment-768297716 Adding quotes to NVM_SYMLINK environment variable: "C:\Program Files\nodejs" instead of C:\Program Files\nodejs.
Install node using node source distribution:
curl -sL https://deb.nodesource.com/setup_[version].x | bash -
apt-get install -y nodejs
[version] = the wanted version. See the repository to choose the correct: NodeSource Node.js Binary Distributions

Why do I keep getting errors with NodeJs and npm when installing yeoman?

I am currently on windows 7 trying to install nodejs and npm to use with git and yeoman. I have uninstalled node and git multiple times and keep getting the same errors
`Welcome to Git (version 1.9.4-preview20140815)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
Jeff#JEFF-PC ~
$ node --version
v0.10.32
Jeff#JEFF-PC ~
$ npm --version
1.4.28
Jeff#JEFF-PC ~
$ npm install --global yo
c:\UsersJeffnpm\yo -> c:\UsersJeffnpm\node_modules\yo\cli.js
> yo#1.2.1 postinstall c:\UsersJeffnpm\node_modules\yo
> node ./scripts/doctor
[Yeoman Doctor] Uh oh, I found potential errors on your machine
---------------
[Error] npm root value is not in your NODE_PATH
[info]
NODE_PATH = :\Users\Jeff\npm\node_modules:\home\npm\lib\node_modules
npm root = c:\UsersJeffnpm\node_modules
[Fix] Append the npm root value to your NODE_PATH variable
If you're using cmd.exe, run this command to fix the issue:
setx NODE_PATH "%NODE_PATH%;c:\UsersJeffnpm\node_modules"
Then restart your command line. Otherwise, you can setup NODE_PATH manually:
https://github.com/sindresorhus/guides/blob/master/set-environment-variabl
es.md#windows
I've tried the command that the yeoman doctor suggested and tried editing the environment variables manually and keep getting these errors. Do I need to edit my .bashrc or .gitconfig files?
Here's my .bashrc content:
export PATH=$PATH:/usr/local/bin
export NODE_PATH=:/Users/Jeff/npm/node_modules
export NODE_PATH=:/Users/Jeff/npm/node_modules:/home//npm/lib/node_modules
If I can change my environment variables or edit my paths please let me know! I greatly appreciate any help you have!
In the second line of your .bashrc you'll note that you have /home//npm/lib/node_modules. Based off the other items in that file I'm betting it should be /Users/Jeff/npm/lib/node_modules or similar.

Cannot run ionic. receives "No command 'ionic' found"

I want to start using the ionic framework, but unfortunately I'm already failing on the first step.
I am running Ubuntu 13.04 and I have node v0.10.25 installed.
I've installed ionic, at described in their docs:
sudo npm install -g cordova
sudo npm install -g ionic
The installation went well, no errors or warnings, but after the installation I type
ionic
and I get the error:
No command 'ionic' found, did you mean:
Command 'ionice' from package 'util-linux' (main)
Command 'sonic' from package 'sonic' (universe)
ionic: command not found
I'm pretty new to ubuntu so I might have something not configured correctly, but I can't find what.
Thanks
for some of you, the two answer above might not work. here's a more general solution for situation where you see "XX" command not found
first check your npm root and npm root -g
the result for the npm root -g should be something like "/usr/local".
if it's not, then you found your problem.
change it by:
npm config set prefix /usr/local
then npm root -g should give you something like /usr/local/lib/node_modules
.
Then go ahead re-install everything with -g
you will be good to go!
Well, I found it finally.
The ionic installation was at /home/guy/npm/bin/ionic, not at /usr/bin/ionic at it should be.
Solved it with:
sudo ln -s /home/guy/npm/bin/ionic /usr/bin/ionic
I solved the problem by cd to my root. Then install ionic as root admin.
$ sudo npm install -g cordova ionic
then run
$ ionic
to see if it's working.
Someone might run into this after trying to change the global library directory of npm to a folder they have permissions to write to in order to be able to install global libs without root permissions.
In that case you might have forgotten to add the new folder to you PATH environment variable.
The whole process of fixing Permissions can be found here.
in case that source disappears here is a copy of the steps:
There are times when you do not want to change ownership of the
default directory that npm uses (i.e. /usr) as this could cause some
problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory
altogether. In our case, this will be a hidden directory in our home folder.
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4 you can also use the corresponding ENV variable (e.g. if you don't want to modify
~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global npm install -g jshint
if you just follow these steps and reinstall all the Global libs there is a good chance that it will start working for you anyways...
Just remember that if you do this, you will save your global libs into the folder created in step 1 instead of the default location in /usr/local or just /usr (depending on your OS flavor i guess?)
First Solution
I recently ran into this issue and the only solution that worked for me was to uninstall both ionic and cordova.
npm uninstall -g cordova
npm uninstall -g ionic
Then just reinstall
npm install -g cordova
npm install -g ionic
Second Solution
I ran into this issue again! This time check your environmental variables.
Run npm bin -g and check if the path returned is in your environmental variables. For me, it prompted that it was not found in the terminal output. I added that path to the environmental variables and restarted the terminal. From there everything started to work again. (source)
I had the same problem with “bash: ionic: command not found”,
then I added:
%USERPROFILE%\AppData\Roaming\npm
to my environment variable’s path, then I reinstalled ionic and cordova and it start working.
For Mac users
1. install the ionic
npm i -g #ionic/cli
2. check npm path
npm root -g
3. copy full path of ionic
Ex. /usr/local/Cellar/node/15.2.1/lib/node_modules/#ionic/cli/bin
4. open this file as administrator "/etc/paths" with nano or whatever editor
Ex. sudo nano /etc/paths
5. Add ionic bin file full path to file ends. And save file.
That's it.
Run npm root -g, copy the result path and add it to the paths file:
sudo nano /etc/paths
Restart your console and it will work.
this worked for me. try adding below to the ~/.bash_profile for mac OSX el capitan users:
NPM_PACKAGES="${HOME}/.npm-packages"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
then run source ~/.bash_profile to reload the profile in terminal.
additional info: node v4.3.1
In my case, I have just uninstalled ionic and then reinstalled it. And it is working fine now.
I also faced same problem but i solved i used following commands on terminal it worked
sudo npm uninstall ionic
then i used
sudo npm install -g cordova ionic#latest
and it worked fine it automatically installs best stabel version of cordova and latest stable version of ionic . for me it installed ionic 3.7.0
and cordova 7.0.1
you can change temporary :
npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2
Run your command to install your package .
open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules
ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.
copy your package file CMD to parent folder "npm"
copy your package folder to parent folder "node_modules"
now run npm config set prefix C:\Users[username]\AppData\Roaming\npm
change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm
now package working correctly with Command line
=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.
The package name has changed from ionic to #ionic/cli!
To update, run: npm uninstall -g ionic
Then run: npm i -g #ionic/cli

Resources