Summary of Linux environment variable configuration methods (differences between .bash_profile and .bashrc)

Summary of Linux environment variable configuration methods (differences between .bash_profile and .bashrc)

Under Linux, if you download and install an application, it is very likely that when you start it, you will get a "command not found" message when you type its name. If you go to the installation target folder every time and find the executable file

It is too cumbersome to perform the operation. In this case, it involves the setting of the environment variable PATH, and the setting of PATH is also an integral part of customizing environment variables under Linux.

Two methods of environment variable configuration:

1) Modify the /etc/profile file

This method is recommended because all users' shells have access to these environment variables. The disadvantage is that it may cause security problems to the system. This is for all users, all shells;

[root@test ~]# vim /etc/profile
....
export PATH=$PATH:/usr/local/mysql/bin

Use the source command to make the changes take effect immediately:
[root@test ~]# source /etc/profile

2) Modify the .bashrc file. This method is safer. It can control the permission to use these environment variables to the user level. Here it is for a specific user. If you need to give a user permission to use these environment variables, you only need to modify the .bashrc file in the personal user's home directory.
[root@test ~]# vim /root/.bashrc
export PATH=$PATH:/usr/local/mysql/bin

[root@test ~]# source /root/.bashrc

It should be noted that:

When setting system environment variables in /etc/profile, the path cannot end with "/", otherwise the entire PATH variable will be incorrect.

[app@test ~]$ vim ~/.bashrc
......
KETTLE_HOME=/data/nstc/kettle3.2
export KETTLE_HOME

Note: After configuring the environment variable, remember to export the variable, otherwise it will be invalid after the source is as follows!
[app@test ~]$ source .bashrc //Make it effective
[app@test ~]$ echo $KETTLE_HOME
/data/nstc/kettle3.2
[app@test ~]$ env
.........
KETTLE_HOME=/data/nstc/kettle3.2

The difference between .bash_profile and .bashrc:

/etc/profile: This file sets the environment information for each user of the system. When the user logs in for the first time, this file is executed. It collects shell settings from the configuration files in the /etc/profile.d directory.
/etc/bashrc: This file is executed for each user who runs a bash shell. This file is read when a bash shell is opened.
~/.bash_profile: Each user can use this file to enter shell information dedicated to their own use. When the user logs in, this file is only executed once! By default, it sets some environment variables and executes the user's .bashrc file.
~/.bashrc: This file contains bash information specific to your bash shell. It is read when you log in and every time you open a new shell.
~/.bash_logout: This file is executed every time you log out of the system (exit the bash shell).

In addition, the variables set in /etc/profile (global) can be applied to any user, while the variables set in ~/.bashrc and other places (local) can only inherit the variables in /etc/profile. They are in a "father-child" relationship.

========================Set terminal login timeout================

How to set the terminal expiration time when logging into a Linux server remotely (i.e., the time after which the terminal will become invalid if there is no operation). Here’s how:
[root@mq-console-nameserver ~]# vim /etc/profile
......
export TMOUT=600
[root@mq-console-nameserver ~]# source /etc/profile

After the above settings, if the terminal logged into this server does not perform any operation within 10 minutes, the terminal will become invalid!

Summarize

This concludes this article about the summary of Linux environment variable configuration methods (the difference between .bash_profile and .bashrc). For more relevant Linux environment variable configuration content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • What is the difference between .bash_profile and .bashrc in Linux
  • Detailed explanation of .bash_profile file in Linux system

<<:  Using jQuery to implement the carousel effect

>>:  Analysis of the usage of loop statements (WHILE, REPEAT and LOOP) in MySQL stored procedures

Recommend

How to Clear Disk Space on CentOS 6 or CentOS 7

Following are the quick commands to clear disk sp...

Native javascript+CSS to achieve the effect of carousel

This article uses javascript+CSS to implement the...

Deep understanding of JavaScript syntax and code structure

Table of contents Overview Functionality and read...

Vue3.0 implements encapsulation of checkbox components

This article example shares the specific code of ...

Notes on element's form components

Element form and code display For details, please...

Css3 realizes seamless scrolling and anti-shake

question The seamless scrolling of pictures and t...

Detailed explanation of MySQL master-slave replication and read-write separation

Article mind map Why use master-slave replication...

Vue uses Canvas to generate random sized and non-overlapping circles

Table of contents Canvas related documents Effect...

In-depth understanding of React Native custom routing management

Table of contents 1. Custom routing 2. Tab naviga...

An article to master MySQL index query optimization skills

Preface This article summarizes some common MySQL...

Detailed tutorial on MySql installation and uninstallation

This article shares the tutorial of MySql install...

Vue template compilation details

Table of contents 1. parse 1.1 Rules for intercep...

Analyze the usage and principles of Vue's provide and inject

First, let's talk about why we use provide/in...

CentOS 8 installation diagram (super detailed tutorial)

CentOS 8 is officially released! CentOS fully com...