Home >Operation and Maintenance >Mac OS >How to add environment variables to mac computer

How to add environment variables to mac computer

王林
王林forward
2020-12-22 10:18:4024878browse

How to add environment variables to mac computer

Usually we probably use the Windows system the most, but there are also many students who like Mac computers. But for friends who are using Mac computers for the first time, configuring environment variables may become a problem. Let’s talk about how to configure environment variables under Mac.

(Learning video sharing: Programming video)

My mac configuration:

How to add environment variables to mac computer

1. Mac system The environment variables, the loading order is:

a. /etc/profile
b. /etc/paths
c. ~/.bash_profile
d. ~/.bash_login
e. ~/.profile
f. ~/.bashrc

2. Among them, a and b are at the system level, which will be loaded when the system starts, and the rest are connected by the user. c, d, e are read in order from front to back. If the c file exists, the following files will be ignored and not read, and so on. ~/.bashrc does not have the above rules, it is loaded when the bash shell is opened. It is recommended to add environment variables in c. The following is also demonstrated by adding environment variables in c. Open Terminal, enter vi ./.bash_profile, press Enter, open the ./.bash_profile file:

How to add environment variables to mac computer

How to add environment variables to mac computer

##Press Enter:

How to add environment variables to mac computer

3. The ./.bash_profile file has been opened, but it is still in view mode and cannot be edited. Enter "i" to enter insert mode

4. You can add environment variables at this time, for example: How to add environment variables to mac computer

export SCALA_HOME=/Users/fushuai/Documents/scala-2.12.4
export PATH=$PATH:$SCALA_HOME/bin

5. After editing is completed, click the "esc key to exit insert mode. ", then enter ":wq!", press Enter, and save successfully.

How to add environment variables to mac computer

#6. Enter “source ./.bash_profile” to make the environment variable take effect.

7. Enter "echo $PATH", check the environment variables, and find that the addition is successful.

How to add environment variables to mac computer

#8. Re-open the terminal and the environment variables will take effect.

Related recommendations:

macos system

The above is the detailed content of How to add environment variables to mac computer. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete