( Excerpt from https://blog.csdn.net/llzk_/article/details/53813266 And then integrate )

1.linux The conditions of the system

Linux It's a multi-user operating system , Every user will have a special running environment when they log in to the system , Usually, the default environment for each user is the same . The default environment is the definition of a set of environment variables . Each user can configure his own running environment by modifying environment variables .

2. Several instructions commonly used to set environment variables

echo

Show environment variables . Format :echo$PATH

export 

Set new environment variables . Format :export New environment variable name = Content

unset

Delete an environment variable

unset MYNAME( Environment variables are usually uppercase )

Classification of environmental variables

1. Permanent variables that work for all users

operation : use vim stay /etc/profile Add the environment variables we want in the file , Go back to the command screen and type source /etc/profile You can successfully set the permanent variables that are valid for all users

This kind of variable works for all users in the system , All users can use such variables . The scope of action is the whole system . 
Setting mode : use vim stay /etc/profile Add the environment variables we want in the file
Of course , This file is only available in root( The super user ) I can't change it until next week . We can do it in etc Use... In the directory ls -l View the users and permissions of this file . 

utilize vim open /etc/ profile file , use export Instruction to add environment variables . 

【 Be careful 】: The new environment variable will not take effect immediately after adding , Unless you call source /etc/profile The document will take effect . Otherwise, it will only take effect the next time you re-enter this user .

2. Permanent variable in effect for a single user

operation : use vim Open file .bash_profile, Add environment variables to the file . Then go back to the command screen and type source .bash_profile You can successfully set persistent variables that work for a single user .

This kind of environment variable is only permanent to the current user . In other words, if the user A Set such environment variables , The only environment variable is A have access to . And for the rest B,C,D,E…. Users and so on , This variable doesn't exist .

Setup method : In the user home directory ”~” Under the hidden file “.bash_profile” Add the environment variable you want in . 
View hidden files : ls -a or ls -al 

​ 
utilize vim Open file , utilize export Add environment variables . Same as above .

Also note that , The new environment variable will not take effect immediately after adding , Unless you call source ./.bash_profile The document will take effect . Otherwise, it will only take effect the next time you re-enter this user .

You can see that I framed two files in red in the picture above ,.bashrc and .bash_profile. In principle, when setting such environment variables, you can add them to either of these two files .

~/.bash_profile It's interactive login Way in bash shell function . 
~/ .bashrc It's interactive non-login Way in bash shell function .

The two settings are roughly the same . Popular point theory , Namely .bash_profile The file will only be read once when the user logs in , and .bashrc It is read every time the terminal is opened for a new session .

3. Temporary valid environment variables

operation : Input export Variable name is enough

This kind of environment variable is only valid for the current shell It works . When we log out or close the terminal and reopen it , This environment variable will disappear . It's temporary .

Setup method : Use it directly export Instruction add . 

Sentiment : Environment variables can be understood as a path . After all linux It's a multiuser system , We can set some environment variables to run our program .

linux Learning notes : More articles on environmental variables

  1. linux —— Learning notes ( Setting of environment variables )

    Catalog Summary of environment variables Files related to environment variables Set the environment variable Attention and related 1. Summary of environment variables environment variable , Simply speaking , It's a variable that stores environmental information . It allows you to execute a script or an application without specifying the full path , For example l ...

  2. Linux Learning notes 1 environment variable 2 vi command

    1 Environmental variables 1.1  modify see take effect System environment variable 1 Files involving system environment variables    -->  .bash_profile --> /etc/profile 2 The file location /root ...

  3. Linux Study ,path, Configuration of environment variables

    Method 1 : 1. View the information about the current environment variable configuration echo $PATH Be careful : echo It means output Add $ Indicates that it is a variable 2. Configure environment commands PATH="$PATH":comdir notes ...

  4. linux —— Learning notes ( Summary )

    A list of notes : One . System knowledge and Basic concepts                     Two . Common operations                   3、 ... and . System management ( Memory . equipment . Service and other management )                   ...

  5. Linux Study notes Linux Summary of environmental variables

    0x00 summary Linux It's a multi-user, multi task operating system , Can be in Linux Set up different running environments for different users in , The specific method is to set the environment variables of different users . 0x01 Linux Classification of environmental variables According to the life cycle ,Lin ...

  6. Linux Learning notes

    Linux Learning notes Please switch web To view , The table is bigger , Method : View >>web Panel view Can't blog Park paste pictures http://wenku.baidu.com/view/bda1c3067fd53 ...

  7. linux Learning notes 2-linux Common commands

    First blog :linux Learning notes 1-ubuntu Installation and basic settings of   In , I've shown you how to install linux operating system , And some basic setup changes . This blog mainly introduces linux Some common terminal commands in ======== ...

  8. Linux Learning notes - Linnaeus Notes-Linux It's time to learn

    Linux Learning notes ... Excellent reference Linux Website : http://www.w3cschool.cn/linux/ http://www.linuxeye.com/ http://linux.vbir ...

  9. linux Learning notes 2 - linux Common commands

    Please mark the original link for reprint :http://www.cnblogs.com/xczyd/p/5543731.html First blog :linux Learning notes 1-ubuntu Installation and basic settings of   In , I've shown you how to install lin ...

  10. Linux  Learn the super detailed basis of note taking linux command  Part 6

    Linux Learn the super detailed basis of note taking linux command by: Give the guest QQ:1033553122 --------------------------------- Pick up Part 5----------------- ...

Random recommendation

  1. Intercollegiate Union Contest

    Every time I open a pit, it's like a premonition of being crushed again The latest news , I used to like Qiao Renliang's < resurrection >... Then he died ... If I feel more sentimental ... It's going to be a river of sadness ... Contest 09/24( lize ...

  2. OpenStreetMap/Google/ Baidu /Bing Tile Map Service (TMS)

    Open source and mature commercial tile map service (TMS  2  WMTS), They all have the following common characteristics , Basically became the standard : (1) Coordinate system :WGS84 (2) Projection : Mercator projection (Marcator, Regular equiangular cylindrical projection ) ------ ...

  3. Java Interview questions ( whole )

    JAVA part What is the reflection mechanism ? Reflection mechanism application (Struts The application of reflection mechanism in ) answer : In operation , For any class , You can know all its properties and methods , For any object, you can call any of its methods , This dynamic access to information to ...

  4. java Programming Properties Class specific role and use

    If you're not familiar with java.util.Properties class , Now let me tell you that it is used to store keys in a file - Value pairs , Where keys and values are separated by an equal sign .( Like the list 1 Shown ). Recently updated java.util.Properti ...

  5. Java Learning notes ( 3、 ... and ): Array

    Array declaration java In language , Arrays are one of the simplest composite data types . An array is a collection of ordered data , Each element in the array has the same data type , You can use a uniform array name and subscript to uniquely determine the elements in the array . int arr1[]; in ...

  6. ios7 sdk New characteristics

    iOS 7 is a major update with compelling features for developers to incorporate into their apps. The ...

  7. Python Built in functions str() and repr()

    Built-in functions str() and repr() (representation. expression , Express ) Or the back quote operator (``) It can easily get the content of the object in the form of string . type . Numerical attributes and so on . str() Function to get a good readability string ( ...

  8. spring boot in active Of profile Will it be combined with standard configuration

    Here's the picture , Two profile The configuration file , A default (application.properties), One is test Of . Active configuration is test. spring.profiles.active=test ste ...

  9. CPP Memory detection

    Yes C.C++ Memory leaks . Check for memory overflow, etc , After two days of data searching , In general, you can use Valgrind, AddressSanitizer, Dr.Memory etc. . among Valgrind It has a great influence on the running speed of the program , shipment ...

  10. C++ Classes and objects ( One )&amp;&amp; Realization offsetof macro &amp;&amp;this The pointer

    One . Catalog 1. Knowledge about objects 2. The definition of a class 3. Class instantiation 4. Class object model 5. Simulation Implementation offsetof macro 6.this The pointer Two . Text 1. Knowledge about objects C Languages are process-oriented , It's about the process , Analyze and solve the problem ...