How to override /usr/local/bin missing from bash profile - bash

I'm trying to override a command that currently defaults to the executable in /usr/local/bin/ffmpeg. I thought I could do it by exporting a PATH to ffmpeg installed with homebrew above the one installed in /usr/local/bin, but when I edit ~/.bash_profile I cannot find the exported path /usr/local/bin. Yet, when I echo the PATH I see /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/ with the exported paths appended to it. Any idea how I can override commands in /usr/local/bin?

/home/user/.profile and other things actually included from global /etc/profile.d, /etc/bash.bashrc and so on, depending on your distributive. They are primary for your shell.
There is no defaults, Linux just searching first occurence of executable in your PATH, so just place directories in correct order in PATH:
Instead of:
PATH=$PATH:/mydirectory/bin
Use:
PATH=/mydirectory/bin:$PATH

Related

permanently add binary to path on mac os

I am trying to permanently add a binary to the path variable on mac os. I have read several posts and blogs, it just does not work.
The question: given a directory /dir which contains an executable foo, how can I make it such that I can execute foo in the commandline without having to type export PATH... etc., and without having to move the foo executable to the bin folder?
I know there exists several scripts that are run on startup and whenever you open a command prompt, I just cannot seem to find the correct one. If I manually execute the export PATH... command and then do foo, it works.
If the export command works for you, just add it to either ~/.zshrc (on zsh) or ~/.bashrc (on bash).

How does my system know to look in a deleted folder for a binary?

If I try to run virtualenv, I get this message:
$ virtualenv
-bash: /Users/me/Library/Python/3.6/bin/virtualenv: No such file or directory
It's not surprising that this happens, because I've removed this directories at an earlier point when trying to clean up my computer from different Python versions. However, how does my system know to look in that directory for virtualenv? I've looked in my bash profile, and there is no mention of virtualenv there.
When you type something your command interpreter has to search the command. Of course it cannot try every possible directory on your system. Then it provides to the user a way to control that process. This is the purpose of the PATH environment variable :
$ echo $PATH
will show you the actual value which looks like dir1:dir2:...:dirn, meaning that commands where searched for in dir1, then dir2, etc. You have to remove the value /Users/me/Library/Python/3.6/bin/ from it. The best way is to edit the .bashrc or .bash_profile file to remove the permanent setting of this variable. Then reconnect.

Did I mess up my PATH? .bash_profile

I am trying to open up files from my terminal using atom. Which resulted in -bash: atom: command not found. I then followed, installing the shell commands from the editor. That resulted in "EEXIST: file already exists, mkdir '/usr/local/bin'" . I've previously tried to follow other recommendations on how to add the subl alias and I guess I tried way too many things, that I didn't understand. Could I have messed up my $PATH ?
When I echo my path this is what it is /bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin.
My bash_profile looks like this when I opened it with nano:
export PATH=/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH
export EDITOR='subl -w'
I don't remember if I added that first line when I tried adding subl.
Should I remove that? I'm also using a MacOS High Sierra.
UPDATE
I removed what I had previously added in my .bash_profile and my path is now: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin.
I then ran the command: sudo ln -s /Applications/Atom.app/Contents/Resources/app/atom.sh /usr/local/bin/atom but got a ln: /usr/local/bin/atom: No such file or directory error
You can remove the export PATH statement from your .bash_profile; it doesn't add anything that isn't already there. (Except maybe /usr/local/sbin, but I would remove that until you can demonstrate a need for it.)
Initially, PATH will include the directories listed in /etc/path:
% cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Any of your shell configuration files can add to the PATH. Assuming you haven't significantly altered your configuration, /etc/profile will run path_helper to add any directories listed in files under /etc/paths.d.
You only need to update PATH if you need to add a directory that is not already there. If atom is located in one of the above paths, you don't need to do anything. It sounds like you attempted to create /usr/local/bin when it already (as it should) exists, then perhaps did not ultimately create the symlink for atom under /usr/local/bin.
Try running just the ln command from the question you linked (using sudo if necessary), then confirm that /usr/local/bin/atom does indeed exist.

mac os x terminal problem faced

oh my god...i faced a big problem...i was created a .bash_profile in ~ folder and then set paths there...bust the big problem is after restarting my bash i see that none of my commands work like LS and RM and etc...
now i dont know how to fix it...some one help me...i need my terminal as soon as possible...
Make sure you are appending to the existing $PATH.
PATH=$PATH:/Users/mthalman/bin
To prevent this happening in the future:
When I edit my environment files (including bashrc, profile, login, and others), I always try starting another shell before quitting my editing environment. This protects me from the possibility of breaking my environment so that I can't log in.
Make sure your PATH includes the usual bin directories: /bin and /usr/bin.
First I would rename ~/.bash_profile to ~/old.bash_profile.
Then open that up in TextEdit (as a plain text document) and verify how you have set your path.
If you would prefer to use vim/emacs/nano/whatever, the act of renaming the file will allow new terminal sessions to use default paths, so from the command line you should be mostly fine.
Then verify you haven't clobbered $PATH as suggested by #Mark Thalman, above.
If you are in a Terminal Window, simply add in the /bin and /usr/bin back in your PATH.
$ PATH="/bin:/usr/bin:$PATH"
That should allow all the basic Unix command to work once more. Or, you can use the full path name for commands:
$ PATH="" #Can't find nothin'
$ ls
bash: ls: command not found.
$ /bin/ls -a #This will work!
. .. .bash_profile foo bar
Don't Reset PATH in your .profile!
As you discovered, you should never reset PATH in your `.bash_profile. Instead, you should always append and prepend to it:
PATH="/usr/local/bin:$PATH"
PATH="$PATH:$HOME/bin"
The first line will prepend /usr/local/bin to PATH which means if a command is in /usr/local/bin and /usr/bin, the /usr/local/bin version will be executed. Many system admins will put alternative base system commands in /usr/local/bin. For example, on Solaris, they might put VIM in /usr/local/bin/vi, so when you edit a file, you're using the improved VIM and not the base VI.
The second line appends your $HOME/bin to the end of $PATH. That means if there's a /bin/ls and you have ~/bin/ls, the /bin/ls will be executed first.
Never set PATH from scratch because each Unix system might have commands that you to access elsewhere in the system. For example, your site might require you to use X11, so you want /usr/X11/bin in your PATH, or you have GIT installed under the /opt/git directory, and you'll need /opt/git/bin in your path.
Sometimes, base utilities like ls might be replaced with upgraded versions of these utilities. On Solaris, you have the base vi and ls command, Most users like the GNU ls command because it uses color and prefer VIM to plain VI. I would included these utilities in /usr/local/bin and prepend that to my PATH.
And now a Word from a Sponsor
As you probably discovered, Finder doesn't list hidden files. That's why you can't see .bash_profile in Finder. You can use some hacks to change this, but it requires you to type them into the terminal window.
I use a Finder replacement called Path Finder. It contains a lot of neat Power User things such as allowing you to see hidden files, treat Packages such as apps as directories, and be able to view protected directories if you have Administrator access. There's a built in terminal and GUI Subversion client.
It's not cheap ($40), but you can download for free and try it out for 30 days.
BTW, I have absolutely no relationship to Cocoatech except as a customer, and I make no money from people buying Path Finder. It's just a tool I use.

conflicting cygwin and windows path

if my windows path looks like this:
c:\ruby\bin;c:\cygwin\bin
then when i go into cgywin and enter "ruby" it will execute the ruby from c:\ruby\bin, failing to find the ruby installed in my cygwin. I have to exclude that path so cygwin would execute the one from /usr/bin.
But i need those 2 paths, since i want to run ruby in windows too.
Anyway to have cygwin have its own path and not inherit those in windows?
thanks.
Add an entry into your .profile to set the path to whatever you want it to be in cygwin.
In cygwin run the command:
$ <favourite text editor eg vi> ~/.profile
Then set the PATH environment variable to whatever you want it to be e.g.:
export PATH=/cygdrive/c/cygwin/bin
NOTE I can't remember whether you can use the c:... version of the path, but if you issue the env command you will see what it should be.

Resources