mac set environment variables

From: http://www.cnblogs.com/shineqiujuan/p/4693404.html
mac generally uses bash as the default shell

Mac system environment variable, the loading order is:
/etc/profile /etc/paths ~/.bash_profile ~/ .bash_login ~/.profile ~/.bashrc
Of course /etc/profile and /etc/paths are system-level, they will be loaded when the system starts, and the latter are the current user-level environment variables. The last three are read in order from front to back. If the ~/.bash_profile file exists, the following files will be ignored and not read. If the ~/.bash_profile file does not exist, it will be read by analogy. later files. ~/.bashrc does not have the above rules, it is loaded when the bash shell is opened.

Unless otherwise specified, the syntax for setting PATH is:
——————————————————-

# separated by a colon
     export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>

(1) Global settings
The following file settings are global and require root privileges when modifying

1) /etc/paths (it is recommended to modify this file globally)
Edit paths, add environment variables to the paths file, one line per line
Hint: When entering environment variables, you don't need to enter them one by one, just drag the folder to Terminal.

2) /etc/profile (it is recommended not to modify this file)
global (public) configuration, no matter which user is, the file will be read when logging in.

3) /etc/bashrc (generally add system-level environment variables in this file)
global (public) configuration, this file will be read when the bash shell is executed, no matter what the method is.

4)
1. Create a file:
sudo touch /etc/paths.d/mysql
2. Open this file with vim (if it is opened by open -t, editing is not allowed):
sudo vim /etc/paths.d /mysql
3. Edit the file, type the path and save it (close the Terminal window and reopen one, you can use the mysql command)
/usr/local/mysql/bin
It is said that this can generate a new file by itself, without changing the variable All are placed in a file named paths for easy management.

(2) Single user settings

1) ~/.bash_profile (add user-level environment variables to any file)
(Note: Linux is .bashrc and Mac is .bash_profile)
If the bash shell is executed in login mode, this file will be read. This file is executed only once! By default, it sets some environment variables
. Set the command alias alias ll='ls -la'
to set the environment variables:

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

2) ~/.bashrc is the same as above

If you want to take effect immediately, you can execute the following statement:
$ source corresponding file
Generally environment variable is changed, it will take effect after restarting.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326777925&siteId=291194637