I downloaded nodejs from nodejs.org on my Mac. When I type node in the command line in the terminal I get the following:
davidd.christie#Davids-MacBook-Pro ~ % node
Welcome to Node.js v12.18.0.
Type ".help" for more information.
> .exit
davidd.christie#Davids-MacBook-Pro ~ % ls
Applications Documents Library Music Postman
Desktop Downloads Movies Pictures Public
davidd.christie#Davids-MacBook-Pro ~ % cd Desktop
davidd.christie#Davids-MacBook-Pro Desktop % ls
UBS Candidate Benefits Modeler.pdf my-express-server
intro-to-node node-course
davidd.christie#Davids-MacBook-Pro Desktop % cd intro-to-node
davidd.christie#Davids-MacBook-Pro intro-to-node % npm init
zsh: command not found: npm
davidd.christie#Davids-MacBook-Pro intro-to-node%
It is my understanding that npm automatically downloads once you download node. I tried to initiate npm and got the following message (please see the above code in typed in the command line):
zsh: command not found: npm
I am not sure what to do from here. I have been looking at some of the code on here. I am so confused as to what to do. I am fairly new to coding. Can someone please help and out step by step as to what I need to do? I would be forever grateful.
It depends on how you have installed node. First check the version of your node.
node --version
It should give your node version. In my case it is v10.15.0. Now to find where this node is coming from use command.
which node
It will give you output as /Users/samundra/.nvm/versions/node/v10.15.0/bin/node. It shows that my node is installed at /Users/samundra/.nvm/versions/node/v10.15.0/. Usually npm and node both are placed at same location $NODE_HOME/bin/node, $NODE_HOME/bin/npm. Here $NODE_HOME is /Users/samundra/.nvm/versions/node/v10.15.0.
If we further check where $NODE_HOME/bin/npm by using
ls -al /Users/samundra/.nvm/versions/node/v10.15.0/bin/npm
We find that it's linked to npm-cli.js
lrwxr-xr-x 1 samundra staff 38 May 11 12:08 /Users/samundra/.nvm/versions/node/v10.15.0/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js
So, npm is symlinked to npm-cli.js which can be found at $NODE_HOME/lib/node_modules/npm/bin/npm-cli.js.
With this information now you can figure out whether your node and npm has been installed properly or not. Furthermore, If this is your first time installing node, try closing and re-opening your terminal. Most terminals need to re-initiate sessions after populating environment variables which are used based on installation method that you have used.
I hope this has answered your curiosity. If you feel so then please do not forget to mark it as answer.
Suggestion:
When you feel you have understood how node and npm work. Then you can move to use Node Version Manager (Nvm). It allows you to install multiple versions of node on same machine. You can switch between them using commands like
nvm list: List available node version
nvm use {node_version}: Install Node version and use it
This is quite helpful when you will have to work on different projects that require different version of nodes.
I faced the same issue. Actually you need to edit your .zshrc file
Open .zshrc file - sudo nano ~/.zshrc
Add source $(brew --prefix nvm)/nvm.sh
Save file and restart terminal
Related
The Node version is 17.7.1. When I run npm -v I get:
bash: /usr/local/bin/npm: No such file or directory
But when I run npm root -g I get:
/usr/local/lib/node_modules
Running npm list -g also gives me the same message as running npm -v.
So, where is it supposed to be and how can I fix this?
There are a few issues as to why this is occuring.
It appears that your computer cannot find the following path (below) to the npm folder, but it can find the global node_modules folder.
/usr/local/bin/npm
This may occur for a number of reasons. Luckily, there are many solutions to these issues.
1. Reinstall Node.js and npm^
The first solution is pretty obvious, and it is to reinstall Node.js and npm^.
The installation process is very simple.
If you are using only the command line, you can install Node.js using the following command. The npm command comes installed with Node.js.
$ sudo apt-get install nodejs
Or, if you want to use the installer, download and run the installer from nodejs.org.
Check the versions of Node.js and npm to see if it has worked.
$ node -v
$ npm -v
The helpful thing about reinstalling Node.js and npm in this case is that, if Node.js and npm weren't installed in the first place (highly unlikely), it will install them.
However, if they were already installed, but then something happened to the installation directory (e.g. it was renamed, moved, deleted or corrupted), then the new installation will most likely have fixed that issue.
2. Add /usr/local/bin/npm to the path (solution worked for OP)
If the first solution didn't work for you, then the next issue that might be occurring might be that /usr/local/bin/npm isn't in your path, which means that bash cannot find it.
To add npm to your path, follow the steps below.
Normally, to get the path with npm, you need to run the following command.
$ npm bin
Obviously, we have to use a workaround. But, we can just use an assumed path for where the binaries of npm are stored, which is...
/usr/local/bin/npm/bin
However, this may vary, so, to be sure that this exists, you can simply type it into the command line.
$ cd /usr/local/bin/npm
Then, you can run the ls command, and see if there are any bin folders or .sh shell scripts that might be used for the path.
$ ls
Make sure you save the binary part for later!
Open the home directory using the following command. This is because the .bashrc file is in the home directory (used in the next step).
$ cd $HOME
Open the .bashrc file using vi (or any file editor of your choice, but vi will be used in this example).
$ vi .bashrc
Then, press the i key for Insert Mode. Type the following in the file.
export PATH=/usr/local/bin/npm/bin:$PATH
In vi, press Esc, then press the following keys: :, w, q, !, Enter.
:wq!
The file is now saved and the editor is closed.
Normally, the .bashrc file is only read when you log in each time. To avoid doing that, you can force bash to read the .bashrc file and update itself. To do this, run the following command.
$ source .bashrc
The bash shell should now be restarted.
These were quite a few steps (four, but many were compressed into one), but if a situation occurred where for some reason npm wasn't adding itself to the path, this solution should fix it.
3. Denied read/write access
Another issue is that your user profile doesn't have the right permissions to read/write to usr/bin/local/npm, or you didn't give npm permissions.
The fix to this solution is very simple.
Run the npm commands you want to run using sudo.
$ sudo npm -v
$ sudo npm list -g
If you want, you can make the commands you run automatically run with sudo.
$ sudo -s
$ npm -v
$ npm list -g
Warning: If you don't have the password for sudo, you can't run any of the commands using sudo above.
This should fix your issue, if denied read/write access is the problem.
There are most likely many more solutions^^, but they might be added later.
^ This is a very usual process, but it has to be added here so that I can be sure that this solution has been tried.
^^ These solutions may be found later and edited to this answer. Edited once.
use this command :
npm list -g
you should see your npm directory at first line
When I tried installing nvm from website -
https://github.com/coreybutler/nvm-windows
everything went good, except the nvm use, even when I execute this command this doesn't seem to do its job properly though no error is thorwn by the terminal(cmd). When I try to use
node -v
it doesn't show the version number of node, that means node is not installed. And same goes witht the
npm -v
, this too doesn't show the version number, it hasn't been finding the executable. Everything works fine, that I install nvm install too. nvm list says there it is, and it donwloads and saves it the its user/appdata/nvm folder,(I checked it). But still cmd can't find the executable. Do I manually need to set the path for the node folder that's located in the roaming/nvm/node folder.
https://github.com/coreybutler/nvm-windows/issues/221#issuecomment-262363222
This comment solved the problem with one go, I guess the key was to use powershell, now node and npm works like smoothie. ;D
What is npm?
Whenever I browse through some project they ask me to run npm command, something like this
npm install -g node-windows
I went through some blog posts to learn about npm and I installed Node.js. However, when I run the above code in Node.js, I get the following errors:
When I browsed further, I came to know that the windows user can run the command from the cmd prompt window, but when I do that I get some output like this:
Which just generate a text file nothing else.
My questions:
How can I get started with the AngularJS2?
How can I run an npm command?
Do I require a command prompt to run the npm command (in Windows), or I can just use Node.js?
When I use the command npm install in my command prompt, I get the following output:
How to get started with the angularJS2
Follow this link and set up the project by following instructions
How to run a npm command
npm stands for Node Package Manager, and therefore you need Node.js installed before you can run npm commands.
Follow this and install the latest version. And restart the command prompt.
Do I require a command prompt to run npm commands (in Windows), or can I just use Node.js?
Yes, you need to run npm commands from the command line (in Windows).
E.g., npm install
You get the warning because there is no package.json file present where you are running the command.
ENOENT stands for Error NO ENTrey
Navigate to the project folder using the following command and then run npm install
cd <projectpath>
The AngularJS 2 website has everything you need to be covered. Their quickstart guide alongside with the quickseed zip file helps a lot.
But, in case you missed some points:
yes, you will need npm/NodeJS. So, download the latest distribution and have a clean installation of it.
you can execute the npm command with its parameters from within the Windows cmd.
the quickseed ZIP file contains all the files you need to see a live and quick example running locally. Unzip it on your workplace and navigate to it using the windows cmd. When inside the root folder of the unzipped package, execute npm install and right after it npm start.
Take the learning path. Step by step, all your questions will be answered.
You need to use an admin prompt for global installation (-g).
This question already has an answer here:
NPM -bash command not found
(1 answer)
Closed 6 years ago.
Using a Mac Os X Yosemite was trying generate some scaffolding and this is what comes back in the bash terminal
-bash: some_command: not found
This happens with most of my commands like run, serve etc when trying to generate or use certain executable commands. General alias’s and commands like mv, ls, rm etc work fine
I’ve checked my $PATH and it seems correct:
$ /bin/echo $PATH
/Users/user_name/.rbenv/shims:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/heroku/bin:/usr/local/bin:/usr/local/sbin:/usr/local/share/npm/bin:/Users/user_name/.rbenv/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin
I checked to make certain npm, node, yomen, grunt etc show as installed with -v and shows updated and installed.
I’ve checked my ~.bash_profile appears and aliases but all seems fine.
The best I can gage is it has something to do possibly with npm and or Node and possibly Homebrew. So I’ve uninstalled, reinstalled and researched any similar like questions out there but nothing seems to work. Hoping someone can point me in the right direction here since I am at a lost. And I am not the best at the environment set up. So might not be looking at something thats staring at me in the face. Thanks in advance.
Make sure to install whatever CLI tool you're trying to use first if you haven't already. For example:
npm install -g yo
That command installs yeoman into the global npm module directory. That directory should also be in your $PATH. To find the directory npm uses, type the following:
npm config get prefix
That will show you what directory npm is installing global modules to. In that directory there should be a bin/ directory with symlinks for any CLI tools that came with a global module you installed. That bin/ directory should be in your $PATH variable for bash to find command line scripts in there.
I'm using NVM to manage my node installations so when I run npm config get prefix my directory is: /Users/chev/.nvm/versions/node/v5.0.0. That's not the standard directory though. If you installed node with the default installer then yours will be different. When I do echo $PATH mine looks like this: /Users/chev/.nvm/versions/node/v5.0.0/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin. Directories in path are separated by colons (:).
A common problem with node on OSX is the need to use sudo with npm commands because of permissions issues in the default global npm modules directory. If you're having issues like that I suggest you also start using something like NVM. NVM allows you to install multiple node versions side by side, but even if you don't need that functionality it's still useful because it configures node & npm so that everything operates out of your home directory at ~/.nvm/ and avoids permission issues. No more sudo.
I recently decided to pick up Node on my personal laptop, which I upgraded to Windows 10, and the Node cli seems to hang when I try to run it.
Simply typing node on the console will not initiate the interface, and to do anything else I need to Ctrl+C out of it.
Additionally, running some npm commands take longer than they used to on my laptop. More noticeably, npm init seems to hang after confirming the information to be written to package.json.
Node version is 4.0.0
npm version is 2.14.2
Are there any known issues with Node and npm on Windows 10?
Edit:
After some troubleshooting, I've figured out the error only happens on Msysgit. Neither of the issues happen on the standard command prompt of Windows.
I had the same issue on Windows 7 with Node version 6.11.0 and Msysgit's MINGW64 terminal window.
The problem was caused by the an alias provided by Msysgit as demonstrated below:
$ alias node
alias node='winpty node.exe'
The solution is to run the command:
$ unalias node
Then node will run correctly.
You can add the unalias node command into your .bashrc file in your HOME directory to make this permanent.
Good luck!
Jeff