Bash: cordova: command not found on mac - apache

I used command sudo npm install -g cordova to install cordova it shows result in terminal/Users/paramesh/.npm-packages/bin/cordova -> /Users/paramesh/.npm-packages/lib/node_modules/cordova/bin/cordova
+ cordova#8.0.0
updated 1 package in 47.732s
while creating project in cordova its bash: cordova not found

In my case, the path of npm was not set correctly. The package was installed on my local path even if I install it globally.
First, check npm path using npm root
If its not /usr/local/lib/node_modules then
set your path using npm config set prefix /usr/local
and again install you package npm install -g cordova

It's strange though that your system cannot find cordova after a global install with sudo. Have you tried reinstalling? If this doesn't help, try the following.
Restart the terminal and type this to check whether your system can find the cordova executable:
which cordova
If you get no output, it means your system cannot find the executable cordova binary. UNIX systems require executable binaries to be placed within the PATH environment variable. Try adding the following line in your ~/.bash_profile file:
$PATH=$PATH:/Users/paramesh/.npm-packages/lib/node_modules/cordova/bin/cordova
If you don't have a ~/.bash_profile, add it to the ~/.bashrc or ~/.profile file, whichever exists already. Then within the terminal you want to call cordova from, type:
source ~/.bash_profile
which cordova
This should give you the location of the cordova binary. Now you can use it.

Related

install packages globally in google cloud platform

I'm trying to install some npm packages globally in google cloud platform each time the shell started.
I added these commands in $HOME/.customize_environment file.
#!/bin/sh
date -u
npm i -g #angular/cli
then, I open the file /var/log/customize_environment to see the log output from $HOME/.customize_environment
I found it executed and the date is displayed (the first line)
but npm couldn't installed with this error npm command not found
npm commands are available after the cloud shell starts, so I guess the file $HOME/.customize_environment is executed before installing node.
I tried to use the full path: /usr/local/nvm/versions/node/v12.14.1/bin/npm i -g #angular/cli, but I got this error
/usr/bin/env: ‘node’: No such file or directory
is there a way to automatically install npm packages globally?
The path env var isn't set or active. Use the full path of NPM location like that
/usr/local/nvm/versions/node/v12.14.1/bin/npm i -g #angular/cli
Be careful. if Cloud Shell update the version of NPM the path will change.
You can also try to add your NPM (without full path) command at the end of the ~/.bashrc file.

How to fix 'command not found' for aws-cdk after running the npm install

I am trying to install the aws-cdk and in the terminal and I run the npm install -g aws-cdk. As stated here After npm runs, I get:
/usr/local/Cellar/node/9.8.0/bin/cdk -> /usr/local/Cellar/node/9.8.0/lib/node_modules/aws-cdk/bin/cdk
+ aws-cdk#0.31.0
updated 1 package in 1.636s
If I try to run cdk I get:
zsh: command not found: cdk
Installing as root worked for me:
sudo npm install -g aws-cdk
Make sure /usr/local/Cellar/node/9.8.0/bin is in your PATH
In my case, I added this to the end of my .bash_profile:
export PATH=$PATH:$(npm get prefix)/bin.
I did that based on information from a different thread.
If you're using nvm to manage your node versions, make sure that the CDK package is being installed in the same version of node you're currently using or the version you want to use.
The OP noted their CDK was getting installed in node/9.8.0:
Check the current node version running: nvm current.
If you see that the CDK installation location is different than the node version indicated by nvm current, you'll need to switch your node version using:
nvm use <node-version-where-cdk-is-installed>
In the OP's case, this would be nvm use 9.8.0.
What worked for me in mac was adding to the path the bin directory of globally installed node modules.
Install aws-cdk by:
npm install -g aws-cdk
Try to run it
cdk
no command found error
make or edit your .zshrc file in your user directory
add line to .zshrc with export PATH=$PATH:/{your_user_path}/.npm-global/bin
execute it source .zshrc
now cdk should work
Pay attention that it is mac based approach.

Installing npm globally

Is it possible to install npm globally and is this a good idea?
I installed npm with the npm install command and was able to run npm start. Then after publishing my project to github I wanted to make sure it would run if someone cloned it, so I cloned it to a different directory on my machine. I then had to run npm install again to install the dependencies. Is it necessary to do this for each project you build locally or is it better and possible to install it globally on your machine?
Thanks
Command line for install npm globally--
npm install -g <package>
For more read from here.
In general, the rule of thumb is:
If you’re installing something that you want to use in your program,
using require('whatever'), then install it locally, at the root of
your project.
If you’re installing something that you want to use in your shell, on
the command line or something, install it globally, so that its
binaries end up in your PATH environment variable.
Details you can read here.
To install a module from npm globally, you'll simply need to use the --global flag when running the install command to have the module install globally, rather than locally (to the current directory).
you can use command:
npm install <module> --globalor npm install <module> -g
note: <module> is the name of the module you want to install globally

fish shell and global npm modules

I'm experiencing some issues with my local environment.
I'm using:
homebrew (1.1.4)
fish shell (2.4)
n version manager (2.1.0)
node
npm
All of the above were initially installed via homebrew.
Issues:
Any globally installed modules cannot be run.
I cannot update npm versions.
The node versions I use regularly are 0.10.48 and 6.9.2 - but mostly 4.6.2.
I've created some aliases in fish to be able to get the the global modules to run. I'd prefer to address the root cause rather than continue applying further bandaids though.
Extra info:
~> npm config get prefix
/Users/me/.npm-packages
~> npm bin
/Users/me/node_modules/.bin
What happens when I try to update npm:
~> npm install -g npm#3
/Users/me/.npm-packages/bin/npm -> /Users/me/.npm-packages/lib/node_modules/npm/bin/npm-cli.js
npm#3.10.10 /Users/me/.npm-packages/lib/node_modules/npm
~> npm -v
2.15.9
When I try to call a global module:
~> gulp
fish: Unknown command 'gulp'
What I've tried in order to fix the global modules:
~> cat ~/.config/fish/config.fish
set fish_user_paths /Users/me/.npm-packages
ls ~/.config/fish/functions
bower.fish ember.fish pm2.fish
~> cat ~/.config/fish/functions/bower.fish
function bower
/Users/me/.npm-packages/bin/bower $argv;
end
Any help you can provide will be greatly appreciated! I've been trying to fix this for awhile now without any luck!
You can use installed npm modules. You just need to add npm global path to the shell. To do that, I ran:
$ npm config get prefix
// Output: /usr/local/Cellar/node/9.2.1
and then, added to my fish/config.fish:
set PATH /usr/local/Cellar/node/9.2.1/bin $PATH
This is the Github related link that helped me solving the problem.
What happens when you install node application globally https://docs.npmjs.com/getting-started/fixing-npm-permissions
Configuring in OSX 10.12.5 with
fish v2.6.0
node v8.1.0
example command in terminal returns both
term~> npm install jshint -g
/Users/username/npm-global/lib/node_modules/bin/jshint ->
/Users/username/npm-global/lib/node_modules/jshint/bin/jshint
the PATH you should have in shell to enable you to execute jshint (installed package) -> pointing to the actual install location
Include line below for configuring PATH in file ~/.profile
export PATH="$HOME/npm-global/lib/node-modules/:$PATH"
My permanent solution (with macOS Mojave and fish 2.7.1):
set -U fish_user_paths /Users/{USERNAME}/.npm-packages/bin $fish_user_paths
Btw, below one works but only in terminal session:
set PATH $PATH /Users/{USERNAME}/.npm-packages/bin
Note: You can find npm-packages path with:
printf "%s\n" $PATH
For me non of this worked, so i installed oh my fish nvm plugin
omf install nvm
I resolved this by completely uninstalling (and deleting any traces of) node, npm and n, uninstalling fish shell and changing to zsh instead.
Afterwards, I installed nvm and used it to restore node on my machine.
Global npm modules now work.

Urturn API ur: command not found

I am trying to install urturn api and write my own expression for urturn.com
following http://webdoc.github.com/urturn-expression-api/#!guides/start
After:
npm install urturn-toolbelt -g
I am trying to run sandbox with:
ur sandbox
and got error:
-bash: ur: command not found
Please help
P.S. I am on Mac Os
thanks
It is likely your nodeJS npm/bin folder that is not included in your PATH.
Can you check your PATH variable?
Node NPM package bin files are all symlinked in the same ./bin folder. If you installed NodeJS using Homebrew (brew install node), it should be /usr/local/share/npm/bin.
You can echo your current path using:
echo $PATH
If the folder above does not appear in the list, check your .bashrc or .bash_profile files and fix any problem.
A fix that is likely to work is to add the following line in ~/.bash_profile
PATH=$PATH:/usr/local/share/npm/bin