Several Methods for setting the path environment variable for MAC: Environment Variable path

Source: Internet
Author: User

Several Methods for setting the path environment variable for MAC: Environment Variable path

Mac generally uses bash as the default shell

The Mac system environment variables are loaded in the following sequence:

/Etc/profile/etc/paths ~ /. Bash_profile ~ /. Bash_login ~ /. Profile ~ /. Bashrc

Of course,/etc/profile and/etc/paths are system-level, which will be loaded when the system starts. The following are the environment variables of the current user level. The last three are read in the previous and subsequent order. If ~ /. Bash_profile file exists, then the following files will be ignored and not read. If ~ /. Bash_profile file does not exist, so it reads the following files accordingly .~ /. Bashrc does not have the above rules. It is loaded when bash shell is opened.

Unless otherwise specified, the PATH syntax is :-------------------

# Export PATH = $ PATH: <PATH 1 >:< PATH 2 >:< PATH 3 >:------: <path n>

(1) Global settings the following file settings are global and the root permission is required for modification.

1)/etc/paths (it is recommended to modify this file globally)

Edit paths and add the environment variable to the paths file.

Hint: when entering environment variables, you don't need to input them one by one. You just need to drag the folder to Terminal.

2)/etc/profile (this file is not recommended) Global (public) configuration. No matter which user, the file will be read at login.

3)/etc/bashrc (generally adding system-level environment variables to this file) Global (public) configuration. During bash shell execution, the file is read in any way.

4)

1. Create a file:

Sudo touch/etc/paths. d/mysql

2. open the file with vim (if it is opened in open-t mode, it cannot be edited ):

Sudo vim/etc/paths. d/mysql

3. edit the file, type the path, and save it. (close the Terminal window and open another one. You can use the mysql Command)

/Usr/local/mysql/bin

It is said that this allows you to generate new files by yourself without storing all the variables in a paths file for convenient management.

(2) individual user settings

1 )~ /. Bash_profile (add user-level environment variables to any file)

(Note: In Linux, It Is. bashrc and Mac is. bash_profile)

This file is read only when bash shell is executed in login mode. This file is only executed once! By default, it sets some environment variables.

SET command alias ll = 'LS-la'

Set environment variables:

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

2 )~ /. Bashrc same as above

To take effect immediately, run the following statement:

$ Source corresponding file

Generally, after the environment variable is changed, it takes effect after restart.

Related Article

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.