OSX differentiate applications with same name in PATH - macos

In OSX, I have added a new path to /etc/paths. It is a path to a medical image viewer application known as rview.
It seems to clash with vim and on typing rview in bash it starts up vim.
But my question is more general, how do you differentiate applications with the same names included in PATH?

The path is evaluated in order; the first matching executable is run.
To edit this, you should change your user profile, not the system-wide configuration. You may have a line similar to this in your ~/.bash_profile file:
export PATH=/usr/local/sbin:/usr/local/bin:$PATH
Just add the path to your application before $PATH and it should work fine. If the line isn't there, create it.
And, if you really want to edit the system paths, just add yours at the top of /etc/paths instead of the bottom.

Related

Why is my mac system's path directory so long?

I just ran the command
echo $PATH
The output was:
/opt/anaconda3/condabin:/usr/local/opt/python/libexec/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Why is it so long? Shouldn't it look more like
/usr/local/bin?
It is quite normal to have a PATH variable that is long. Yours contain some duplicate entries but this is not a real problem.
If you execute a command without specifing a path the shell searches in each path specified in the PATH variable to find it. In your example it search in /opt/anaconda3/condabin and after that in /usr/local/opt/python/libexec/bin and so on.
It is normal to have multiple places for executables and thus multiple entries in the PATH variable separated with colon. Often third party software like Anaconda in your example adds it own folder to the PATH variable.
Have a look at /etc/paths, /etc/paths.d and your shell profile where those path might be added.
And from a security standpoint your PATHS could be risky if /opt/anaconda3/condabin or /usr/local/opt/python/libexec/bin is writeable by the user/others as anybody can place malicious executable there masking the system supplied ones in /bin or /usr/bin.
If not absolutely neccessary third party pathes should be added to the end as they normally shouldn't replace existing binaries.

iverilog environment set up on macbook

I tried to make iverilog command s.t I can run verilog program on my Macbook Air.
After few steps for installing the files, the tutorial told me to type:
export PATH=~/bin:/usr/local/iverilog/bin
It worked in terms of iverilog command, i.e, I can compile .v file. However, normal command like ls, man,etc.
I guess it is the problem of the PATH of the command sets, which means those normal unix command is not located.
Can someone tell me how to fix it and I dont need to export the PATH everytime?
You didn't add your paths to the current paths established by the OS. Instead, you replaced it with your paths. This is what you need to do in order to add paths to your PATH variable:
export PATH=$PATH:~/bin:/usr/local/iverilog/bin
The $PATH part is your current PATH value, which is added (concatenated actually) to the list of new paths you want to add. This is turn is assigned to PATH variable.
To make this additions permanent, you may want to add the above line to the end of your .profile file, or .bash_profile (whatever you have in OS X)
You can also do as this:
http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/
Which says that you can edit the file /etc/paths and add whatever paths you want to add, one per line, then save that file and your added paths are available. In this case, just remember to use absolute paths. That is, paths starting with / . The first one you use: ~/bin is not an aboslute path. You need to convert it to an absolute path. To do this, remember that ~ is a shortcut to your HOME directory: something like /Users/myloginname. Type echo $HOME to find it out.

Where is the default terminal $PATH located on Mac?

I have been looking throughout the system but I cannot find it. When I do echo $PATH I get the stuff I added, plus the default path. I do not have a .profile, and I do have a .bashrc, but the default path is not in there. I am looking for it just to know where it is located because all the tutorials explain that its in .profile... but what if you don't have one? Where is it located then? Anybody have any ideas?
If you do sudo man path_helper, it talks a bit about how it puts the path together. You might look in /etc/paths and /etc/paths.d. I did, and found what I was looking for.
Many system-wide settings including PATH are set in /etc/profile which is read in by bash at startup. On Mac OS X this file usually uses path_helper to set PATH. This utility in turn reads the information from other system configuration files under /etc (see path_helper manpage).
Note that even if you disable the reading of the initialization files by bash (e.g. with command-line options like --noprofile) it will still inherit the environment of the parent process.
If you start at /etc/profile, it should look something like this:
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
It's testing to see if the file exists and if so, executes it. If you execute it by hand, you'll get something like this:
PATH="/usr/bin:/bin:/usr/sbin:/usr/local/bin:/usr/X11/bin"; export PATH;
I believe that's what you're looking for. So it comes from /etc/profile, which in turn calls an executable that sets the path.
As mentioned in the accepted answer, the $PATH is built by first looking into the content of the file /etc/paths, and then looking into every file in the folder /etc/paths.d. So, the $PATH in the pre-installed bash system installation contains every entry in these files, as well as in other shell types.
However, because in the latest Mac OS versions the default shell is zsh, I followed a couple of tutorials in which the writer avoided to change the $PATH for the bash shell, and simply added new entries to the $PATH by editing ~/.zshrc the following way:
export PATH=/path/available/only/for/zsh/shells:$PATH
The above command adds /path/available/only/for/zsh/shells to the $PATH, and the added path will only be available in zsh shells.
I hope this helps someone who, like me, had too many entries in the $PATH in zsh shells, and couldn't figure out where they were coming from!
The .profile file on Mac is located in your user folder: ~/Users/youruser/
However, the .profile file is hidden. You can press Command+shift+. (command, shift, dot) while on Finder to see them.
There's one important fact I only realized today while debugging a problem: the profile settings (.bash_profile etc.) are only read by login shells. They are not read by the processes that are used to launch your applications.
You launch your applications in diverse ways: click the icon in /Applications, or type the name in Spotlight search, or click an icon in the Dock ... In all those cases, the application itself (i.e the binary or shell script inside the application) is launched by launchd without any parent shell. Meaning that your profile is not run and that your custom settings (PATH, environment variables ...) will be ignored.
That can cause all sorts of trouble, for example if you setup you environment to use a specific version of Java: your application will not see that and use the "default" java, which will be the one with the highest version number.
In my case, the problem is that my application was crashing when run via the application launcher, but runs fine when run from a terminal window ... The reason was that I had a custom path that included some libraries required by the application, but that was not available when the application was run by the launcher.
The solution I used was to symlink the libraries needed into /usr/local/lib

VIM_APP_DIR environment variable on Mac OS X Lion

I am looking to enable my terminal with the MacVim/mvim command so that I can access macvim through the terminal.
Following directions, I have downloaded and unzipped the MacVim files.
To be able to access MacVim through the terminal, one requires to set the VIM_APP_DIR environment variable with the value being the location of mvim script or the MacVim path.
By attempting the following command:
export VIM_APP_DIR = "the filepath"
I carried out printenv and VIM_APP_DIR does not exist in the set of environment variables.
Now that sounds more like a problem within a problem. The problem is I am unable to find a way to enable my Mac OS X Lion to be Vim powered and the above was the recommended route towards glory, however leave glory, the actor wasn't even there (VIM_APP_DIR).
First, you may not have to set the VIM_APP_DIR environment variable if you put the MacVim.app bundle in one of the “usual” locations:
~/Applications/ (the Applications folder in your home directory)
/Applications/ (the main Applications folder on the computer)
/Applications/Utilities/
It actually checks a few more locations, too: some relative to the location of the mvim script, and in a vim/ directory under the described directories.
In most cases, you should only need to set VIM_APP_DIR if mvim complains like this:
Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR enviro
nment variable to the directory containing MacVim.app.
Second, if you have to set VIM_APP_DIR (because you keep MacVim.app in an “unusual” location), the value of the environment variable should be the directory that contains MacVim.app, not the location of MacVim.app or mvim itself.
For example: If, you moved MacVim.app to /MyFavoriteApps/MacVim.app and have mvim available somewhere in your PATH, then you would need to set VIM_APP_DIR to /MyFavoriteApps (not /MyFavoriteApps/MacVim.app).
Third, in bash (the shell you are probably using), parameter assignments must not have spaces around the equal sign. It should look like this:
export VIM_APP_DIR=/MyFavoriteApps
If the pathname has spaces or special characters, then you may need to quote it. Single quotes are a good choice because they represent a literal string (you can include any character except a single quote itself).
export VIM_APP_DIR='/My Favorite Apps'
Last, you will probably want to put this “assignment and export” in your shell’s initialization file to make sure the value is set in all your future shell instances. A good choice is usually ~/.bashrc.
I don't know where you're getting this from. All that is required is to put the mvim script in your path, e.g., /usr/local/bin, and MacVim.app in a "normal" location such as /Applications or ~/Applications. Full list here: https://github.com/b4winckler/macvim/blob/master/src/MacVim/mvim (line 20).

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.

Resources