Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of configuring environment variables under Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces what are the methods of configuring environment variables under Linux. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

On linux, if you download and install an application, it is likely that the prompt "command not found" will appear when you type its name at startup. If you go to the installation target folder every time, find the executable file

It is too tedious to operate, in this case, it involves the setting of the environment variable PATH, and the setting of PATH is also a part of customizing the environment variable under linux.

Two ways to configure environment variables:

1) modify / etc/profile file

This method is recommended because all users' shell has the right to use these environment variables, but the disadvantage is that it may cause security problems to the system. This is for all users, all shell

[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 more secure, it can control the permissions to use these environment variables to the user level, here 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 their personal user's home directory.

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

Export PATH=$PATH:/usr/local/mysql/bin

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

It is important to note that:

When setting the system environment variable in / etc/profile, the path cannot end with a "/", otherwise it will cause the entire PATH variable to go wrong.

[app@test] $vim ~ / .bashrc

.

KETTLE_HOME=/data/nstc/kettle3.2

Export KETTLE_HOME

Note: after configuring the environment variable, remember that export outputs this variable, otherwise the following source will not work!

[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 environment information for each user of the system and is executed when the user logs in for the first time. And collect shell settings from the configuration file in the / etc/profile.d directory.

/ etc/bashrc: execute this file for each user running bash shell. When bash shell is opened, the file is read.

~ / .bash_profile: each user can use this file to enter shell information dedicated to their 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.

~ / .bashrc: this file contains bash information specific to your bash shell, which is read when you log in and every time you open a new shell.

~ / .bash_logout: execute this file every time you exit the system (exit bash shell).

In addition, the variables (global) set in / etc/profile can act on any user, while the variables (local) set in ~ / .bashrc and so on can only inherit the variables in / etc/profile, they are "father-son" relationship.

= set terminal login timeout =

Remote login to the linux server, how to set the terminal failure time (that is, after how long does not operate, the terminal is about to fail). The methods are as follows:

[root@mq-console-nameserver ~] # vim / etc/profile

.

Export TMOUT=600

[root@mq-console-nameserver ~] # source / etc/profile

After the above setting, the terminal that logs on to this server does not do anything within 10 minutes, then the terminal will become invalid!

The above is all the contents of the article "what are the methods of configuring environment variables under Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report