None of the commands are working in my Terminal

I have Mac OS Catalina (version 10.15.7) and I observed that none of the commands are working in my terminal. Tried following commands:


$ java -version

-bash: java: command not found


$ touch ~.bash_profile

-bash: touch: command not found

Posted on Sep 8, 2021 10:57 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 10, 2021 10:33 AM

A few corrections:


1) You don't need to export PATH multiple times. One is enough.


2) These commands are resetting PATH and annuling all the previous ones:


PATH=$ANDROID_HOME/build-tools

PATH=$ANDROID_HOME/platform-tools

PATH=$ANDROID_HOME/tools


You can do more than one at a time, but don't forget to concatenate with the previous value of PATH.

For example, these three could become


PATH=$ANDROID_HOME/build-tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH


This adds these three directories at the head of the PATH.

If you omit the final :$PATH, then the previous value of PATH is discarded.



3) Same thing here, add :$PATH at the end


# Setting PATH for Appium

PATH="/usr/local/lib/node_modules/appium"

export PATH


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export PATH


4) These are duplicates, delete one of them.


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"

export PATH


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"

export PATH








18 replies
Question marked as Top-ranking reply

Sep 10, 2021 10:33 AM in response to rajiv212

A few corrections:


1) You don't need to export PATH multiple times. One is enough.


2) These commands are resetting PATH and annuling all the previous ones:


PATH=$ANDROID_HOME/build-tools

PATH=$ANDROID_HOME/platform-tools

PATH=$ANDROID_HOME/tools


You can do more than one at a time, but don't forget to concatenate with the previous value of PATH.

For example, these three could become


PATH=$ANDROID_HOME/build-tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH


This adds these three directories at the head of the PATH.

If you omit the final :$PATH, then the previous value of PATH is discarded.



3) Same thing here, add :$PATH at the end


# Setting PATH for Appium

PATH="/usr/local/lib/node_modules/appium"

export PATH


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export PATH


4) These are duplicates, delete one of them.


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"

export PATH


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"

export PATH








Sep 11, 2021 1:11 PM in response to rajiv212

rajiv212 wrote:

When I run "echo $PATH" command in terminal, it shows:

$ echo $PATH
/usr/local/lib/node_modules/appium

What should be the correct value of $PATH. Also, how to change the value of $PATH?

The PATH variable has a size limit. (This is from an older Bob Harris post - Limit of File-Path in OSX 10.13+ - Apple Community).


Macmini-i18:Downloads $ getconf PATH_MAX /

1024


and typically PATH is appended to at the end, not at the beginning, to avoid losing SYSTEM variables. For example,


Macmini-i18:Downloads $ echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS

Macmini-i18:Downloads $ export PATH=$PATH:/usr/local/lib/node_modules/appium

Macmini-i18:Downloads $ echo $PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/lib/node_modules/appium


Once you lose the SYSTEM parts, ⛈ happens. This is on macOS Catalina.


sw_vers

ProductName:	Mac OS X

ProductVersion:	10.15.7

BuildVersion:	19H1323


Please be careful how you set up the PATH variable.

Sep 10, 2021 9:24 AM in response to BobHarris

Bob:

Apparently, the OP is using bash - as per his first post.


rajiv212:

zsh is the default shell, but as per your first post, the error message clearly indicates you are running bash:


-bash: touch: command not found


Incidentally, there is NO problem in running bash. Some people may point out, quite correctly, that the version of bash that Apple ships with macOS is not up to date, but for most users, this is irrelevant. Those who need to care about it know how to use zsh or install a more recent bash. For everyone else, it does not matter.


It seems very odd that none of /bin, /usr/bin, /usr/local/bin are in your PATH. I don't know how that came to happen.


Also: the word "export" is missing in that .bash_profile. Otherwise, the value of PATH will not be passed on to subshells, etc.


There should be


export PATH=...


instead of just PATH=...


For a quick solution, you could add a line like


export PATH=/bin:/usr/bin:/usr/local/bin


at the TOP of the file.

Then type

. ~/.bash_profile



Sep 9, 2021 7:15 AM in response to rajiv212

rajiv212 wrote:

I have Mac OS Catalina (version 10.15.7) and I observed that none of the commands are working in my terminal. Tried following commands:

$ java -version
-bash: java: command not found

$ touch ~.bash_profile
-bash: touch: command not found



https://support.apple.com/guide/terminal/use-environment-variables-apd382cc5fa-4f58-4449-b20a-41c53c006f8f/mac

Sep 10, 2021 8:19 AM in response to VikingOSX

Hi Viking,


I was using this Mac mini from past 4 years. I have a bash file (.bash_profile) already present in the system with all the all the mandatory path set. Please find below the path I set in the .bash_profile file:


#For Java

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home

PATH=$PATH:$JAVA_HOME/bin


# For Android SDK

export ANDROID_HOME=/Users/dreammapper/Library/Android/sdk

export ANDROID_SDK=$ANDROID_HOME

PATH=$PATH:$ANDROID_HOME/build-tools

PATH=$PATH:$ANDROID_HOME/platform-tools

PATH=$PATH:$ANDROID_HOME/tools


It was working fine. I was able to use commands in Terminal.

The issue started when my OS got updated to Catalina (10.15.7). Now, none of my commands are working.

I checked the default shell. It is now zsh.

Is it happening because of this??

Sep 10, 2021 10:18 AM in response to Luis Sequeira1

Hi Luis,


Please find below the ".bash_profile" paths that I am using for your reference. If you find any mistake then please point it out, I will update the file accordingly:


------------------------------------------------------------------

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home

PATH=$PATH:$JAVA_HOME/bin


export M2_HOME=/Applications/Maven/apache-maven

export M2=$M2_HOME/bin

PATH=$M2:$PATH


export ANT_HOME=/Applications/Ant/apache-ant

PATH=$PATH:$ANT_HOME/bin


export ANDROID_HOME=/Users/dreammapper/Library/Android/sdk

export ANDROID_SDK=$ANDROID_HOME

PATH=$ANDROID_HOME/build-tools

PATH=$ANDROID_HOME/platform-tools

PATH=$ANDROID_HOME/tools

export PATH


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"

export PATH


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"

export PATH


# Setting PATH for Appium

PATH="/usr/local/lib/node_modules/appium"

export PATH


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export PATH


---------------------------------------------------


Sep 11, 2021 5:10 AM in response to Luis Sequeira1

Hi Luis,


I have made changes as per your suggestions.

Ex:

I added $PATH at the end of all the paths and updated the ANDROID_HOME path.

Also, removed the duplicate Python path.


Though, most of the commands have started working in terminal but I have some queries which are as follow:

  1. When I open an emulator in Android Studio it throws a pop-up that says, " AVD Manager: unable to locate adb.".

Is there any solution for this pop-up?


2. In your comment you suggested to export the path only once. Should I add "export path" at the end of each path or at the last line of the file?


Please check the below .bash_profile changes and do let me know if any other change is required.


-----------------------------------------------------

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home

PATH=$JAVA_HOME/bin:$PATH


export M2_HOME=/Applications/Maven/apache-maven

export M2=$M2_HOME/bin

PATH=$M2:$PATH


export ANT_HOME=/Applications/Ant/apache-ant

PATH=$ANT_HOME/bin:$PATH


export ANDROID_HOME=/Users/dreammapper/Library/Android/sdk

export ANDROID_SDK=$ANDROID_HOME

PATH=$ANDROID_HOME/build-tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH

export PATH


# Setting PATH for Python 3.9

# The original version is saved in .bash_profile.pysave

PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin:$PATH

export PATH


# Setting PATH for Appium

PATH=/usr/local/lib/node_modules/appium:$PATH

export PATH


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:$PATH

export PATH

Sep 11, 2021 8:25 AM in response to Luis Sequeira1

Hi Luis,


adb is located in "platform-tools" folder in the following location:


/Users/dreammapper/Library/Android/sdk/platform-tools/adb


path is already mentioned in the bash_profile.

PATH=$ANDROID_HOME/build-tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH


Also, I ran "find /usr $ANDROID_HOME -name 'adb'" command and the output is as follow:


find: /usr/sbin/authserver: Permission denied

/Users/dreammapper/Library/Android/sdk/sources/android-30/com/android/server/adb

/Users/dreammapper/Library/Android/sdk/sources/android-29/com/android/server/adb

/Users/dreammapper/Library/Android/sdk/ndk-bundle/python-packages/adb

/Users/dreammapper/Library/Android/sdk/platform-tools/adb



Sep 11, 2021 10:16 PM in response to Luis Sequeira1

Hi Luis,


Thanks for understanding the problem and giving solution!!!

Now, I am able to use commands in Terminal.

Also, I tried finding solution for the error pop-up " AVD Manager: unable to locate adb." that appears on opening emulator in Android Studio.

It can be solved by giving the adb path explicitly in emulator's "Extended Controls > Settings > Use detected ADB location" box.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

None of the commands are working in my Terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.