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 completely uninstall node and npm on mac

npm uninstall sudo npm uninstall npm -g If you en...

MySQL green version setting code and 1067 error details

MySQL green version setting code, and 1067 error ...

Basic reference types of JavaScript advanced programming

Table of contents 1. Date 2. RegExp 3. Original p...

Summary of the benefits of deploying MySQL delayed slaves

Preface The master-slave replication relationship...

MySql common query command operation list

MYSQL commonly used query commands: mysql> sel...

Use CSS's clip-path property to display irregular graphics

clip-path CSS properties use clipping to create t...

Tomcat first deployment web project process diagram

Put your own web project in the webapps directory...

Vue implements seamless scrolling of lists

This article example shares the specific code of ...

About the selection of time date type and string type in MySQL

Table of contents 1. Usage of DATETIME and TIMEST...

How does MySQL implement ACID transactions?

Preface Recently, during an interview, I was aske...

Getting the creation time of a file under Linux and a practical tutorial

background Sometimes we need to get the creation ...

foreman ubuntu16 quick installation

Quickstart Guide The Foreman installer is a colle...

Implementation of proxy_pass in nginx reverse proxy

The format is simple: proxy_pass URL; The URL inc...