Linux adds some Python paths to environment variables

Reference: https://www.myfreax.com/how-to-add-directory-to-path-in-linux/

Add the directory to the PATH environment variable

In some cases, you may need to add additional directories to your $PATH environment variable. For example, some programs may be installed in different directories.

But in order to run it without specifying the absolute path to the executable. Therefore, you need to add the directory to your $PATH environment variable.

Assuming that there is a bin directory in the home directory, to add the directory to the PATH environment variable, please run the command export PATH = "PATH environment variable, please run the command export PATH="P A T H environment variable , please run the command ex p or tP A T H="HOME/bin:$PATH"。

Now you can run the app by simply typing the name of the executable binary. However, this change is only temporary and only valid in the current shell session.

export PATH="$HOME/bin:$PATH"

Persist PATH

The export command is used to set environment variables, which are only available in the current shell session. To make the changes permanent, you need to set the $PATH environment variable in the PATH configuration file.

In most Linux distributions, when the system boots, environment variables are read from /etc/environment and /etc/profile and the ~/.bashrc file.

The global configuration files are /etc/environment and /etc/profile. If you want to set the $PATH environment variable for all users of the system, please modify it in these two files.

The global configuration files are /etc/environment and /etc/profile. If you want to set the $PATH environment variable for all users of the system, please modify it in these two files.

When you set the PATH environment variable for the specified user , please modify the PATH environment variable in the /.bashrc file. Please modify the PATH environment variable in the ~/.bashrc fileWhen using the PATH environment variable , please modify the PATH variable in the /.bas hrc file. If Zsh is  used, the file is ~/.zshrc .

In this tutorial, we will set the PATH environment variable in the /etc/environment file, that is, for all users.

Instruction echo PATH=“ HOME / bin : HOME/bin:HOME/bin: PATH” | sudo tee -a /etc/environment will add the directory $HOME/bin to the PATH environment variable, use echo command and tee command.

echo PATH="$HOME/bin:$PATH" | sudo tee -a /etc/environment

Now that we have persisted the PATH environment variable, if you have not used the export command to set PATH, then the current shell session PATH environment variable will not be modified.

You can run the source command which will load environment variables into the current shell session. Of course, you can also use the export command to set the PATH environment variable.

To determine whether the PATH environment variable is set correctly, you can run the command echo PATH to view the current PATH to view the currentP A T H View the value of the current PATH environment variable.

source /etc/environment
echo $PATH

Conclusion
Setting the PATH environment variable in Linux is very simple. This allows you to run your command or application from any directory without having to type the full path to the executable.

The same instructions will work for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, and Linux Mint. Feel free to leave a comment if you have any questions.

Guess you like

Origin blog.csdn.net/qq_21237549/article/details/130321403