Background of 0.
In the work often need to install some development tools, such as Java, MongoDB, etc., for convenience, often modify environment variable Settings.
My machine is CentOS Linux, record my method.
1. Set environment variables
1.1 Export in Environment Variables
Export is used to define a variable format: export {variable name} {variable value}
Example:
Export MONGO_DB_HOME = "/ root/mango/mongo - Linux - x86_64 rhel70-4.2.5" export PATH = $MONGO_DB_HOME/bin: $PATHCopy the code
MONGO_DB_HOME variable is defined above, and its value is a path address. MONGO_DB_HOME: MONGO_DB_HOME: MONGO_DB_HOME: MONGO_DB_HOME: MONGO_DB_HOME: MONGO_DB_HOME: MONGO_DB_HOME: MONGO_DB_HOME
1.2. Modify environment variables
The export directive can be used on the console or in scripts. It can be applied in one of three scenarios:
1.2.1 This parameter is applicable only to scenarios where the current user is valid
Method: Modify the bashrc file of the current user. Scope: Current User This approach is more secure by limiting access to these environment variables to the user level, in this case for a specific user.
If you need to give a user permission to use these environment variables, you can simply modify the.bashrc file in the user’s home directory.
vi ~/.bashrc
Copy the code
Finally, add the environment variable content defined above by export below the end of the file.
1.2.2 Environment variables that apply to all users
Method: Modify the /etc/profile file. If you use this method only for development use on your computer, since all users’ shells have access to this environment variable, it may cause security problems for the system. This is for all users, all shells
vi /etc/profile
Copy the code
Finally, add the environment variable content defined above by export below the end of the file.
1.2.3 Only the current command line/console is available
Use export directly on the current command line/console to define the scope of the environment variable: Current command line The scope of this variable is only available on the current command line/console. This is rarely used.
END