Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install npm packages globally and path fix doesn't work

I get a bash:command not found even after getting success installing npm packages globally w npm install -g react-native or the like.

I followed https://medium.com/@jagatjyoti.1si13cs040/npm-g-install-npm-package-not-working-as-desired-why-why-why-19795abf0b59 verbatim, and tried using sudo, however after install I still get the bash:command not found

What is wrong here and how can I install global npm packages on my mac?

like image 223
blue Avatar asked Sep 19 '25 01:09

blue


2 Answers

This error is because npm is not able to put the globally installed packages on the right path, you can fix it easily by removing ~/.npmrc, fellow the steps below it should resolve your issue.

Possible fix

check if you have anything related to files with prefix in ~/.npmrc.

  1. Open your terminal and enter

    Enter in terminal

    ~/.npmrc
    

    Possible output

    zsh: permission denied: /Users/{...}/.npmrc
    
  2. Now remove them with

    Enter in terminal

    rm -rf ~/.npmrc  
    

Now you can install any global package and use them

npm install --global expo-cli

Now that it's removed, npm install -g should put expo in the right place, and everything should Just Work :-)

Link to original answer

like image 104
Rehan Avatar answered Sep 20 '25 15:09

Rehan


By default, the executables such as react-native, when installed globally, should be located in /usr/local/bin. Try to run /usr/local/bin/react-native and if that works, check whether you have /usr/local/bin included in your PATH variable (echo $PATH);

If you can't find react-native, or any other globally installed executable at the above mentioned location, run

npm bin -g

which will tell you where to look. Once you know the location, repeat the above mentioned steps - try to execute it specifying the full path and check whether the location is included in the PATH.

To include an entry in the PATH. Go to your home directory and add this entry (line of code)

export PATH=$PATH:/Users/myuser/bin

to .bash_profile or .bashrc file. If that file doesn't exist, create one (restart terminal afterwards).

like image 36
Matus Dubrava Avatar answered Sep 20 '25 16:09

Matus Dubrava