Set environment variables in three ways in Linux

Source: Internet
Author: User

Set environment variables in three ways in Linux

1. In windows, environment variables must be configured for many software installations, such as jdk installation. If environment variables are not configured, run the javac command in a directory other than software installation, the file cannot be found. A similar error is reported.

2. What are environment variables? Simply put, it is to specify a directory. when running the software, the relevant program will find the relevant files according to the directory. The most practical function for setting variables is that you do not need to copy some dll files to the system directory. The path system variable is a series of paths for the system to search for dll files.

In linux, If you download and install an application, it is very likely that the prompt "command not found" appears when you type its name. It is too cumbersome to find the executable file in the installation directory every time. This involves setting the environment variable path, and the Path setting is also an integral part of customized environment variables in linux.

Three methods for setting environment variables in linux:

To add a PATH to $ PATH, perform the following operations:

1. Set in the console. This method is not supported, because it only works for the current shell and is invalid for another shell:

$ PATH = "$ PATH":/NEW_PATH (disabling shell Path will restore to the original path)

2. Modify the/etc/profile file. If your computer is used only for development and usage, this method is used because all users' shells have the right to use this environment variable, security issues may occur to the system. This is for all users, all shells

Add: export PATH = "$ PATH:/NEW_PATH" at the bottom of/etc/profile"

3. Modify the bashrc file. This method is more secure. It can control the permissions to use these environment variables to the user level. This method is for a specific user, if you want to grant a user permission to use these environment variables, you only need to modify. you can use the bashrc file.

Add the following content:

Export PATH = "$ PATH:/NEW_PATH"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.