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

Detailed explanation of basic data types in mysql8.0.19

mysql basic data types Overview of common MySQL d...

HTML left and right layout example code

CSS: Copy code The code is as follows: html,body{ ...

vue.config.js packaging optimization configuration

The information on Baidu is so diverse that it...

Do you know the difference between empty value and null value in mysql

Preface Recently I found that my friend's met...

The hottest trends in web design UI in 2013 The most popular UI designs

Time flies, and in just six days, 2013 will becom...

Share MySql8.0.19 installation pit record

The previous article introduced the installation ...

How to configure Jupyter notebook in Docker container

Jupyter notebook is configured under the docker c...

Teach you how to get the pointer position in javascript

The method of obtaining the position of the point...

MySQL 8.0.20 installation and configuration detailed tutorial

This article shares with you a detailed tutorial ...

How to pop up a temporary QQ dialog box to chat online without adding friends

In fact, this is very simple. We add an a tag to ...

Linux nohup to run programs in the background and view them (nohup and &)

1. Background execution Generally, programs on Li...

Problems encountered when updating the auto-increment primary key id in Mysql

Table of contents Why update the auto-increment i...

MySQL 8.0.11 MacOS 10.13 installation and configuration method graphic tutorial

The process of installing MySQL database and conf...

Nginx handles http request implementation process analysis

Nginx first decides which server{} block in the c...