ubuntu environment variable settings

Linux is a multi-user operating system. After each user logs in, there will be a dedicated operating environment.

Usually, the default environment for each user is the same, and this default environment is actually the definition of a set of environment variables.

Users can customize their own operating environment by modifying the corresponding system environment variables.

Common environment variables:

PATH: determines which directories the shell will look for commands or programs in

HOME: current user home directory

MAIL: refers to the current user’s mail storage directory.

SHELL: It refers to which kind of Shell the current user is using.

HISTSIZE: refers to the number of historical command records saved.

LOGNAME: refers to the login name of the current user.

HOSTNAME: refers to the host name, if many applications use the host name, it is usually obtained from this environment variable.

LANG/LANGUGE: It is a language-related environment variable. Users who use multiple languages ​​can modify this environment variable.

PS1: is the basic prompt, which is # for root users and $ for ordinary users.

PS2: It is an auxiliary prompt, the default is “>”.

/etc/profile ~/.profile ~/.bashrc /etc/bash.bashrc etc. are all configuration files for setting environment variables. The configuration of these files will be read into the currently running system when the system starts or the user logs in , enter the env command on the command line to view the current environment variables.

1. Environment variables

Environment variables in Linux include system-level and user-level. System-level environment variables are system variables that every user who logs in to the system must read, while user-level environment variables are environment variables that are loaded when the user uses the system. Therefore, the files for managing environment variables are also divided into system-level and user-level.

1. System level:

1) /etc/environment:

is the first file the system reads at login to set environment variables for all processes. When the system uses this file, it does not execute the commands in this file, but assigns VALUE to KEY according to the code in the KEY=VALUE mode. Therefore, if you want to define the PATH environment variable in the file, you only need to add a line like PATH=$PATH :/xxx/bin can be the code.

2) /etc/profile:

It is the second file executed when the system is logged in and can be used to set environment variables for all users of the system. This file is generally called /etc/bash.bashrc file.

3) /etc/bash.bashrc:

A system-wide bashrc file that is executed for every user running the bash shell. This file is executed every time the user opens a shell.

Notice:

/etc/environment is the environment for setting the entire system, and /etc/profile is the environment for setting all users. The former has nothing to do with the logged-in user, and the latter is related to the logged-in user. After these two files are modified, it is generally necessary to restart the system to take effect.

2. User level (these files are in the home directory)

1) ~/.profile:

It is the profile file corresponding to the currently logged-in user and is used to customize the personal working environment of the current user.

Each user can use this file to enter the shell information dedicated to his own use. When the user logs in, the file is executed only once! By default, he sets some environment variables and executes the user’s .bashrc file. Here is the recommended place to put personal settings

2) ~/.bashrc:

It is the bash initialization file corresponding to the currently logged-in user. When the user opens the shell, the system will execute this file once. You can set this file normally.

According to the above description, the order of execution of these files should be:…

The post ubuntu environment variable settings first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9334
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment