Several ways for MAC to set environment variable path

Source: Internet
Author: User

Mac typically uses bash as the default shell

Environment variables for Mac systems, loaded in the order:

/etc/profile/etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.BASHRC

Of course/etc/profile and/etc/paths are system-level, the system boot will be loaded, the following are the current user-level environment variables. The next 3 are read in the previous order, if the ~/.bash_profile file exists, then the next few files will be ignored, if the ~/.bash_profile file does not exist, and so on to read the following file. ~/.BASHRC does not have the above rule, it is loaded when the bash shell is opened.

If no special instructions are specified, the syntax for setting path is: ——————————————————-

#中间用冒号隔开ExportPATH=$PATH: <path 1>: <path 2>: <path 3>:------: <path N>

(a) Global settings The following file settings are global and require root permissions when modified

1)/etc/paths (global recommendation to modify this file)

Edit paths, add environment variables to the paths file, one line at a path

Hint: When entering environment variable, do not enter one by one, just drag the folder into Terminal.

2)/etc/profile (recommended not to modify this file) global (public) configuration, regardless of which user, the file will be read when logged in.

3)/ETC/BASHRC (typically adds a system-level environment variable to this file) global (public) configuration, which is read by the bash shell, regardless of the way it is executed.

4)

1. Create a file:

sudo touch/etc/paths.d/mysql

2. Open this file with vim (if it is opened in open-t, edit is not allowed):

sudo vim/etc/paths.d/mysql

3. Edit the file, type the path and save (Close the Terminal window and reopen one to use the MySQL command)

/usr/local/mysql/bin

It is said that it is possible to generate new files on their own, without having to put the variables in a paths file for easy management.

(ii) Individual user settings

1) ~/.bash_profile (add user-level environment variable in any file)

(Note: Linux is. BASHRC and Mac is. Bash_profile)

This file will not be read until the bash shell is executed in login mode. The file is only executed once! By default, he sets some environment variables

Set command aliases alias Ll= ' Ls-la '

Set Environment variables:

PATH=/opt/local/bin:/opt/local/sbin:$PATH

2) ~/.BASHRC Ibid.

If you want to take effect immediately, you can execute the following statement:

$ source The corresponding file

After the general environment variable is changed, the restart takes effect.

Several ways for MAC to set environment variable path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.