10

I have installed expo-cli globally but when I try to run any expo code like expo start from anywhere, I get:

zsh: command not found: expo

echo $PATH returns:

/Users/amitg/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/amitg/.npm-global/bin

I am using macOS, catalina.

brainfog
  • 101
  • 1
  • 1
  • 3

9 Answers9

14

The correct command to run expo in macOS these days is npx expo.

e.g.

npx expo init my_app

If expo-cli is not installed, it will provide you with instructions to install

Someone Special
  • 12,479
  • 7
  • 45
  • 76
8

The answer is pretty simple.

just add npm binaries to your path

  1. echo $PATH
  2. export PATH=$PATH:~/.npm-global/bin
  3. source ~/.profile or source ~/.bash_profile

That's It, It will work now, Just go check it expo init myproject

Abilogos
  • 4,777
  • 2
  • 19
  • 39
Savio Martin
  • 81
  • 1
  • 3
  • After the first 2 steps, it worked for me. Thanks. – anas.p Jun 04 '21 at 11:38
  • I have a mac and this also did the trick for me. Thank you for this! – Andrew Colin Oct 27 '21 at 02:48
  • This was super helpful thanks! A note for other people - run command 1, then command 2, then run command 1 again and you should see the .npm-global/bin on the end, if you do run command three and check again - it should work – Frankinstyyn Aug 29 '22 at 08:58
4

FOR MACOS

So I recommend your echo $PATH command should be /usr/local/bin. Probably you have install Node on the website via .pkg you have downloaded. I have tried to remove and reinstall multiple times but it wasn't work on MacOS Catalina. I highly recommend to install via NVM. Okay I got you at first it sounds like you don't want any third party dependency to install more than Official website of NodeJS, alright I understand your concern, but I have tried for 2 hours straight and it is not worked. NVM is not really that bad, it is helpful and handy and you don't have to reinvent the wheel. I will show you very simple way, no mess up.

So I recommend you to remove and uninstall it first:

  1. brew uninstall node
  2. which node //if this not found or return empty it means you have removed it
  3. sudo rm -rf /usr/local/bin/node
  4. sudo rm -rf /usr/local/lib/node_modules/npm/
  5. brew doctor
  6. brew cleanup --prune-prefix

Then:

  1. brew uninstall --ignore-dependencies node
  2. brew uninstall --force node

MAKE SURE YOU ARE DEACTIVATE ANY VIRTUAL ENVIRONMENT ***:

  1. brew update
  2. brew install nvm

Then create folder for NVM (no need to care which directory you are in now)

  1. mkdir ~/.nvm

Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later) by nano ~/.bash_profile: (Marks my word, ADD belows line to bash_profile or zsh, not running those two commands below, ADD THEM!!!)

  1. export NVM_DIR=~/.nvm
  2. source $(brew --prefix nvm)/nvm.sh

Add the NVM Directory Paths to Your Shell Profile (When Needed)

  1. nano .zshrc
  2. export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  3. Type CTRL + x in your Mac
  4. Type Shift + y in your Mac
  5. Hit Enter or Return key

Then you need to QUIT/CLOSE ALL TERMINAL entirely to make effect

To see what Node versions are available to install run:

  1. nvm ls-remote You will see list of Node version available. I recommend to install any node version with Latest LTS (green color text)

For me, I just needed the latest point release of Node version 12.8.4 LTS stable released during my answer for you so I ran

  1. nvm install 12.18.4 or nvm install --lts
    Otherwise a useful reference in 2022: https://heynode.com/tutorial/install-nodejs-locally-nvm/

Verify your node version:

  1. node --version

THEN FINALLY INSTALL expo cli

  1. npm install --global expo-cli

Check expo installation:

  1. expo --version

I am a student I tried many ways and this work for me and I hope I would be part to help you. Comment if sth still go unplanned.

Chanrithisak Phok
  • 1,590
  • 1
  • 19
  • 29
0

I am getting the same loop. This is how you fix your expo-cli.

  1. npx uninstall -g expo-cli
  2. npx update (in your project directory).

Works like a charm. No endless loop. No editing the bash or zsh files.

Baxter
  • 312
  • 4
  • 6
0

I had the same issue: the following command worked for me on mac :

  1. sudo npm install -g expo-cli

  2. sudo npx create-expo-app

Macbook run

-1

I had the same problem when switched from bash to zsh, I solved it by checking at my .bash_profile (wich is located at ~/.bash_profile) and I found this export:

 export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

given that in bash everything worked correctly I decided to copy the export and replace default export in .zshrc file (wich is located at ~./zshrc)

Your ~/.zshrc file should look something like this:

# If you come from bash you might have to change your $PATH.
#export PATH=/usr/local/bin/npm:$PATH
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Then restart your terminal by pressing cmd + Q and you're done, hope this helps.

Jeyson Mg
  • 150
  • 1
  • 6
-1

If none of the above work for you try:

sudo npm install --unsafe-perm -g expo-cli

hopefully this helps.

Relie Essom
  • 959
  • 9
  • 15
-1

use "sudo yarn global add expo-cli" instead of "yarn global add expo-cli"

-1

When i got a new macbook i faced the same challange. Here's how i fixed the issue:

alias expo="npm config get prefix/bin/expo"

Now try expo start again, it should work.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 31 '22 at 15:14