-bash: sudo: command not found Mac OS X (EC2 CLI prob?) - macos

Getting the error:
-bash: sudo: command not found
echo $PATH outputs PATH:EC2_HOME/bin
I'm running Mac OSX 10.8.3
That seems wrong even for a n00b like me.
How do I fix my $PATH and return my computer to it's former self?

As stated in the comments the right files to set up your $PATH variable are: ~/.profile or ~/.bash_profile
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
In this way when you re-enter in the console your PATH will work fine.
You can add other directories to your $PATH as you like.
If you just copy and past that line in an active console you just set the PATH variable temporary, when you logout and login again you will loose your path, so add it in your ~/.bashrc file.

I'm not sure how you've managed to get into that state, though this article explains how you can set your path.
If it helps, the output from my echo $PATH is: -
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

go to shell
choose new command
put this : sudo vim .bash_profile
then put : export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH

This worked for me:
echo $PATH
Followed by:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Related

zsh: command not found: mv (I'm trying to move composer.phar)

I'm trying to follow a course on Udemy (laravel). I just downloaded XAMPP (I'm on macOS Monterey) and I edited the ~/.zshrc file and added export PATH=/Applications/XAMPP/bin
After that I installed composer which worked successfully, but now when I try to run this command: mv composer.phar /usr/local/bin/composer the shell responds with: zsh: command not found: mv.
Does anyone know how to fix this?
You messed up your PATH. Do a
path+=(/Applications/XAMPP/bin)
instead of the export PATH=... you are using now. And since you want to fiddle with the PATH in your .zshrc, I also suggest to do a
typeset -aU path
near the top of your .zshrc to avoid duplicate PATH entries when you launch an interactive subshell.
The file mv was not found in your PATH, is your PATH variable setup correctly?
Enter echo $PATH to see your PATH variable.
Try /bin/mv to see if the binary file exists.

Terminal doesn't work (bash commands aren't recognizable)

I have macOS Sierra version 10.12.6
I tried to add a path using the terminal. I entered source ~/.bash_profile and then a text file opened and I entered my path.
But then the terminal stopped responding and bash commands are not recognizable anymore.
If I enter: source ~/.bash_profile nothing happens.
And if I enter any environment related command an error message shows: -bash: printenv: command not found
How can I fix this?
You've probably messed up your path. When you're setting a path it's important to append to it rather than overwrite, or you lose access to all the system paths; /usr/local/sbin, /usr/local/bin, /usr/sbin etc. When setting a new path make sure you use:
$PATH=$PATH:/path/to/add
You can fix this by removing the line from .bash_profile where you overwrote the path. Please paste the contents of .bash_profile if this does not work.
You've replaced $PATH with some of your values and you might not be able to update .bash_profile because of the unavailability of nano. Use the following command to access nano and environment variables.
export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
After using the command you can use nano ~/.bash_profile to fix the problem.

Terminal commands can not be found OSX

A majority of terminal commands don't work, for example .
ls
sudo
vi
with the error -bash: ls: command not found my path is echo $PATH
“/Users/username/usr/local/bin I get the feeling that “ should not be there but not sure how edit it.
What should the path be and how do I get the path to stay the same?
You need to add more paths to your $PATH variable. Try running whereis ls and check where is the binary of the command.
You can add more paths like this: export PATH=$PATH:NEW_PATH
I had a similar experience recently where a lot of my terminal commands were not being found despite being clearly saved in my bash_profile. After lengthy process of elimination I realised that the issue was caused when I tried to export a new path. The error that I had made was putting a space in the command. So I had to change
export SOMETHING = /path/to/something.apk to
export SOMETHING=/path/to/something.apk
So I would recommend you check all your path declarations to ensure you don't have any white spaces. Also don't forget to source your bash_profile or what ever type of command line shell you use.

I have to type export PATH=~/anaconda/bin:"$PATH" everytime I rerun the terminal

I have installed the Anaconda for Mac, but there is something wrong with me:
when I type the commandwhich conda or which ipython, I get conda not found and ipython not find
Then I find this command export PATH=~/anaconda/bin:"$PATH" works for me. It solves the problem above, but everytime I rerun the terminal the problem is still there, I have to type it again.
so I want to find a way to solve the problem fundamentally
I have tried to add it into the ~/.bashrc, ~/.profile, ~/.bash_profile, but these don't work for me.
Try this in .bash_profile
export PATH="$HOME/anaconda/bin:$PATH"
Then try launching a new terminal and running:
echo $PATH
The output should start with /anaconda/bin:
If that still doesn't work... A work around might be to invoke bash after running terminal i.e. type "bash". Which should cause bash to launch with .bash_profile
I run on MacOs Catalina 10.15 and this did the trick for me:
shell is zsh !
$ source /Users/myprofilename/anaconda3/bin/activate
then
$ conda init zsh
the new anaconda documentation also highlights this:
Make sure you're not using ZShell or another form of a shell. If the case you'd have to add the path to your respective shell file, e.g .zshrc.
sudo xed /etc/environment
after open this archive add :/home/youruser/anaconda3/bin
If you're using ZShell follow the steps below:
In your terminal type open ~/.zshrc
Add the following to the file export PATH=/opt/homebrew/bin:$PATH
Save your file and then run the following command source ~/.zshrc
Please note that the homebrew path on Apple silicon is /opt/homebrew/bin

Basic command lines on Mac terminal not working

I changed the bash profile while trying to install mongodb and none of my command lines are working on terminal. I read online that I need to fix the $PATH but I can't even access it when none of my commands are working.
Help?
Mistakenly I also ran into same problem where to resolve this I had to reset my PATH variable to basic settings as below :
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin"
Once you set PATH variable now you can open the .bash_profile file in same terminal session only and make changes accordingly. This will resolve your problem.
Ok I found the answer from here:
"Open Terminal, and go to File (or Shell) -> New Command. Type in open -e .profile (or substitute some other file instead of .profile), and hit Run. That should open TextEdit with the file you want to fix; you can remove the offending lines there."
in my case i typed in nano .bash_profile and that allowed me to edit my bash profile and fix the issue.
can't use terminal from error in .bash_profile
Run this in terminal:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Resources