Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global Node Packages Installed to Wrong Directory

I'm trying to install Hexo globally using npm. When I run npm install -g hexo-cli I'm informed that it was installed to /Users/myusername/.node/bin/hexo -> /Users/myusername/.node/lib/node_modules/hexo-cli/bin/hexo

The problem comes in when I run hexo init blog and the hexo command is not found.

I installed Node and npm with Homebrew, so when I run which node and which npm, the results are /usr/local/bin/node and /usr/local/bin/npm respectively.

I'm thinking that I still have leftover files and directories from when I installed Node without homebrew, but I don't want to start deleting things without fully knowing the repercussions. Would I be safe to delete all files located in the /Users/myusername/.node/ directory? I can't figure out why npm is not installing to the proper directory.

like image 838
Punt Speedchunk Avatar asked Jul 08 '16 14:07

Punt Speedchunk


People also ask

How do I change the location of a global node module?

js documentation and found that it can be changed very easily using a simple "npm config" command. For example: npm config set prefix "E:\node_modules", From the next time onward, every global installation will save the node modules in "E:\node_modules" folder.

Where do global node packages get installed?

Path of Global Packages in the system: Global modules are installed in the standard system in root location in system directory /usr/local/lib/node_modules project directory. Command to print the location on your system where all the global modules are installed.

Where does node install global packages Windows?

The global packages will be installed under the active Node version lib/node_modules folder. The $HOME variable points to your user directory in the system. You can also use the where nvm command to find your NVM installation location.

How do I check if a node package is globally installed?

Also, if you want to check if the particular package is installed globally or not, you can hit the below-mentioned “npm list -g” command followed by the package name that you want to check.


1 Answers

After a little digging, I found that my npm prefix variable was pointing do the wrong directory, left behind by the old Node installation. I ran npm config get prefix to see where it was pointing.

I set the new prefix value using npm config set prefix /usr/local. Homebrew is symlinked with this directory via /usr/local/bin. I uninstalled hexo-cli and reinstalled through npm, and now it works perfectly.

like image 94
Punt Speedchunk Avatar answered Oct 15 '22 13:10

Punt Speedchunk