node.jsterminalnpmhomebrewhexo

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.


Solution

  • 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.