Configuration of environment variables in MAC

Source: Internet
Author: User
Tags jconsole

1. Environmental variables Introduction 1.1 The role of environmental variables

What is the use of environment variables and global variables?

1.1.1 Using Scenario 1

Let's take a look at this one. Using Scenario 1, we have a program Java that needs to read a file (/data/file.txt).
Then we need to do the following steps when running:

    1. CD-To-Java directory;
    2. Execute Java commands;

      However, when we need to use multiple tools at the same time, such as Java, Maven, Git and so on, and many machines, we usually need a lot of tedious CD operations. Configuring environment variables allows us to run these scripts quickly.

1.1.1 Using Scenario 2

What if we have JDK1.7, JDK1.8, and need to switch often?
You can configure local variables such as:

export JDK1.7=/usr/apps/jdk1.7export JDK1.8=/usr/apps/jdk1.8export PATH=$JDK1.7/bin

In this way, when you change, you don't need to change the whole thing, and change the part.

1.2 Role of environmental variables

OK, with the above introduction, we can probably know what is the use of environmental variables. The utility is that you can access the contents of the required tool directory in the various directories of the operating system, which is similar to the idea of Windows desktop, and is equivalent to having a shortcut to the desktop throughout the system.

2. MAC environment variable Configuration

Before explaining the MAC environment variable configuration, you can open the DOS box and enter
"Echo $PATH" to see what's in the current PATH.
The result of the individual is this:

localhost:/ Sean$ echo $PATH/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Sean/Software/hadoop/hadoop-2.2.0/bin:/Users/Sean/Software/Scala/scala-2.11.8/bin:/Users/Sean/Software/Spark/spark-2.0.2-bin-hadoop2.7/bin

As you can see, "/usr/local/bin,/usr/bin,/users/sean/software/hadoop/hadoop-2.2.0/bin" are loaded as environment variables in my directory.
So below I will explain how this thing should be configured.

2.1 Precedence of environment variable files

The priority of its configuration file is as follows:



~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
2.2 MAC Configuration Environment variables where

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)

A global (public) configuration that reads the file when logged on, regardless of the user.

3)/ETC/BASHRC (typically add system-level environment variables to this file)

Global (public) configuration, which will be read by the bash shell, regardless of the way it is executed.

4) ~/.bash_profile (typically add user-level environment variables to this file)

Each user can use the file to enter shell information dedicated to their own use, and when the user logs in, the file executes only once!

2.3 Common Operational Commands 2.3.1 operating system judgment
    1. The first thing to know is what kind of SHELL you use for Mac OS x, using the command echo $SHELL
      If the output is: CSH or TCSH, then you are using C Shell.
      If the output is: bash,sh,zsh, then your use may be a variant of the Bourne shell. Before Mac OS X 10.2, the default is C
      Shell. The default is Bourne Shell after Mac OS X 10.3.
    2. If it is a Bourne Shell.
      Then you can add the environment variables you want to add to your home directory under the. Profile or. Bash_profile, if there is no relationship added to it, if one is not generated.
2.3.2 Modifying the Host file
sudo vi /etc/hosts
View and add path environment variables under 2.3.3 Linux

The format of path is:
Path= $PATH::::--:, separated by colons.

2.3.4 Add the PATH environment variable:
[root@localhost u-boot-sh4]#export PATH=/opt/STM/STLinux-2.3/devkit/sh4/bin:$PATH
2.3.5 View the PATH environment variable:
[[email protected] u-boot-sh4]#echo $PATH/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
2.3.6 Operation Example
    • Change the path by editing the startup file.
# vim /etc/profile
    • At the end of the document, add:
export PATH="/opt/STM/STLinux-2.3/devkit/sh4/bin:$PATH"

Save, exit.

    • To take effect immediately please run:
#source /etc/profile

No error is successful.

If you want to take effect immediately, you can execute the following statement: "$ source. Bash_profile (This is the file name.) When the environment variable changes, it takes effect the next time the user logs on.

3. Soft Connection

In addition, many small partners may have discovered that some files are accessed directly on Mac without setting environment variables. What is this for? The answer is to use a soft connection.

3.1 Viewing the Load file

You can use the Cat command to view the paths file

localhost:/ Sean$ cat etc/paths/usr/local/bin/usr/bin/bin/usr/sbin/sbin

The answer is that the Mac automatically loads the paths directory and automatically loads the files under those folders, so using a soft connection to create a soft connection under these folders can achieve the same effect.

3.2 Soft Connect view
ls -li

406876 LRWXR-xr-X1 root Wheel7379. jar/system/library/frameworks/javavm. Framework/versions/current/commands/jar406877 LRWXR-xr-X1 root Wheel7979Jarsigner/system/library/frameworks/javavm. Framework/versions/current/commands/jarsigner406878 LRWXR-xr-X1 root Wheel7479Java/system/library/frameworks/javavm. Framework/versions/current/commands/java406879 LRWXR-xr-X1 root Wheel7579Javac/system/library/frameworks/javavm. Framework/versions/current/commands/javac406880 LRWXR-xr-X1 root Wheel7779Javadoc/system/library/frameworks/javavm. Framework/versions/current/commands/javadoc406881 LRWXR-xr-X1 root Wheel7579Javah/system/library/frameworks/javavm. Framework/versions/current/commands/javah406882 LRWXR-xr-X1 root Wheel7579Javap/system/library/frameworks/javavm. FRAMEWORK/VERSIONS/CURRENT/COMMANDS/JAVAP406883 LRWXR-xr-X1 root Wheel7679Javaws/system/library/frameworks/javavm. framework/versions/current/commands/javaws406884 LRWXR-xr-X1 root Wheel7479Jcmd/system/library/frameworks/javavm. framework/versions/current/commands/jcmd406885 LRWXR-xr-X1 root Wheel7879Jconsole/system/library/frameworks/javavm. framework/versions/current/commands/jconsole406886 LRWXR-xr-X1 root Wheel7379Jdb/system/library/frameworks/javavm. framework/versions/current/commands/jdb406887 LRWXR-xr-X1 root Wheel7579Jdeps/system/library/frameworks/javavm. framework/versions/current/commands/jdeps406888 LRWXR-xr-X1 root Wheel7479Jhat/system/library/frameworks/javavm. framework/versions/current/commands/jhat406889 LRWXR-xr-X1 root Wheel7579Jinfo/system/library/frameworks/javavm. framework/versions/current/commands/jinfo406890 LRWXR-xr-X1 root Wheel7379JJs/system/library/frameworks/javavm. framework/versions/current/commands/jjs406891 lrwxr-xr-x 1 root wheel 7 9 jmap -/system/library/frameworks/java VMS. Framework/versions/current/commands/jmap406892 lrwxr-xr-x 1 root wheel 7 9 JMC -/SYSTEM/LIBRARY/FRAMEWORKS/JAVAVM. FRAMEWORK/VERSIONS/CURRENT/COMMANDS/JMC 

3.3 Soft Connection setup and testing
ln -s /data/kafka  /kafka

-li11373698 lrwxr-xr-x   1 root wheel 11 1 19 18:09 kafka -> /data/kafka

4. References

[1]. MAC can set the location of environment variables, view and add PATH environment variables
[2]. Environment variable settings for MAC
[3]. Build a soft connection under Linux
[4]. Linux Soft Connect and hard links

Configuration of environment variables in MAC

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.