Author Topic: [FAQ] Editting '.bashrc', '.profile' or '.bash_profile' to set the PATH.  (Read 466758 times)

Paula

  • Administrator
  • Hero Member
  • *****
  • Posts: 467
    • View Profile
    • My GPS Division profile
'.bashrc', '.profile', and '.bash_profile' are hidden files that may be used for user-defined settings for the bash shell. Traditionally '.profile' (or '.bash_profile') is used for environment settings, such as setting the user's PATH variable, and '.bashrc' is used for terminal settings, such as aliases. alphaMELTS (and Adiabat_1ph 3.1; see footnote*) tries to use the .profile file to set the user's PATH. However, if the file exists, e.g. if MacPorts is installed, or if '.bash_profile' exists (which will be read by the system instead of '.profile') then the user may need to edit '.profile' or '.bash_profile' manually to put the links directory into their PATH. The install.command or install.pl script will tell you if it thinks this is the case.

As the file(s) are hidden from Finder it is difficult to open them from TextEdit in the usual way. Instead open the Terminal program. If you already have a Terminal window open, e.g. the one opened by install.command, then you can use the Apple Key + n to open a new window. By default it should open in your home space (you can type 'pwd' to check). If you type 'ls -a', where '-a' is for 'all', you will be able to see the hidden files, which have names beginning with a '.'. If '.bash_profile' exists you should edit that, otherwise edit '.profile'. Type 'open .profile' (substitute '.bash_profile' if appropriate) and you should find that it opens in your default text editor. If your default text editor is not TextEdit, you can force it to open that by typing 'open -a TextEdit .profile' instead.

[You can also use 'open .' to open the directory in Finder. This is not very useful in this case, as hidden files won't show, but it can be a quick way to open output files when you are running alphaMELTS...]

There are various formats for modifying the PATH, any of which are fine. Comments are denoted by '#' so you can miss out those lines if you like.

  • If you have MacPorts installed then you can modify the lines that the MacPorts installer changed in your '.profile' file to add your links folder e.g.
    Quote
    # MacPorts Installer addition on date_and_time: adding an appropriate PATH variable for use with MacPorts.
    export PATH=/opt/local/bin:/opt/local/sbin:your_links_folder_here:$PATH
    # Finished adapting your PATH environment variable for use with MacPorts.

  • Or you can copy and paste (Apple Key + c, and Apple Key + v respectively) from the install.command / install.pl window e.g.:
    Quote
    # ~/.profile: executed by the command interpreter for login shells.
    # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
    # exists.

    # set PATH so it includes user's private bin if it exists
    if [ -d "your_links_folder_here" ] ; then
        PATH="your_links_folder_here:$PATH"
        export PATH
    fi

  • Or you can copy and paste from the profile example on the alphaMELTS GitList server. If your links folder is not in the default location then you will need to replace each occurrence of '$HOME/bin' with the actual location:
    Quote
    # ~/.profile: executed by the command interpreter for login shells.
    # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
    # exists.

    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$HOME/bin:$PATH"
        export PATH
    fi

When you are done you need to log off and on again, or type 'source ~/.profile' (though you will need to type that in every Terminal window you open until the next time you log in). You can type 'echo $PATH' to check whether the links folder has indeed been added to the PATH or rerun install.command / install.pl to get the same information - it doesn't matter what you enter for the installation folder if you abort the installation...

If your machine is older (or very new - see the reply below), or if it is a university machine then you should check whether bash, tcsh, or zsh is the default shell. One way to do this is to open the Terminal program and type 'echo $0' (that is 'zero', not uppercase 'o') at the command line. If it says '-tcsh' or '-zsh' then you will need to type 'bash -l' and press enter (that is lowercase 'L', not 'one') each time you open Terminal, before starting the run_alphamelts.command script. See the documentation for more details.

If there are any problems, please do not hesitate to post a reply or e-mail for assistance.

Paula

*In Adiabat_1ph version 3.0 the path was set using a combination of '.bashrc' and '.profile' / '.bash_profile'. This was intended to make it easier to run adiabat_1ph for users who had tcsh, instead of bash, as their default shell. At the time (2011), a significant minority of users were in this situation but now (2015) it is rare. alphaMELTS tries to keep things simple for the majority instead.
« Last Edit: April 23, 2020, 02:46:11 pm by Paula »

Paula

  • Administrator
  • Hero Member
  • *****
  • Posts: 467
    • View Profile
    • My GPS Division profile
In macOS Catalina the default shell is zsh, but if you upgraded from Mojave then you may still have bash. One way to check is to open the Terminal program and type 'echo $0' (that is 'zero', not uppercase 'o') at the command line. If it says '-zsh' then you will need to type 'bash -l' and press enter (that is lowercase 'L', not 'one') each time you open Terminal, before starting the run_alphamelts.command script. See the documentation for more details.