简体   繁体   中英

zsh: command not found: react-native - MacOS

I am trying to start react-native but I get the following error zsh: command not found: react-native when I write react-native init firstApp .

I tried the following guide: react-native: command not found

But I have two main issue:

First I do not understand which path to use/export

React-native has been installed here:

/Users/cisco/.npm-packages/bin/react-native -> /Users/cisco/.npm-packages/lib/node_modules/react-native/local-cli/wrong-react-native.js 

Second

In the guide it is written to run:

export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"   
react-native init appName  
cd appName   
react-native run-ios

I do not get how to:

1) What to write after export PATH=

2) Should I add my path somewhere? If yes, how can I do so? I tried running touch ~/.bash_profile; open ~/.bash_profile touch ~/.bash_profile; open ~/.bash_profile to add my path.

Inside it I have:

# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/cisco/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/cisco/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/cisco/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/cisco/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

Once you help me in finidng out the right path do add, can I simply add it in the file below the line # <<< conda init <<<?

Solved it!

Steps:

  1. Run npm list -g | head -n 1 npm list -g | head -n 1

It will give you a path like/similar to the following: /Users/{YOUR_USER_NAME}/.npm-packages/lib

  1. Change that path by substituting /lib with /bin:$PATH so that you get: /Users/cisco/.npm-packages/bin:$PATH

  2. Run export PATH="/Users/{YOUR_USER_NAME}/.npm-packages/bin:$PATH"

Since you are using zsh. You can add export PATH=/Users/cisco/.npm-packages/bin/react-native:$PATH in ~/.zshrc

This operation work for me very well. Just follow the instruction below.

The default interactive shell is now zsh. To update your account to use zsh, please run

chsh -s /bin/zsh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM