[Linux] sets Environment Variables

Source: Internet
Author: User

[Linux] sets Environment Variables

Setting environment variables in Windows is very easy. For example, right-click my computer> advanced system Settings> environment variables, select Path, and click "edit" to enter the content you want to add. You can add some command line commands that you want to run directly. For example, in java, the bin directory under jdk should be put up.

However, it is not that simple in Linux.

Take Ubuntu as an example. There are two ways to set environment variables:

Press Ctrl + Alt + T to open the terminal and enter:

 

sudo gedit /etc/environment
Enter the password, open the configuration file of the system variable, and modify the content.

 

Add system environment variables directly at the end

: The path you want to set.

Use the colon (:) to separate folders.

Save and exit.

 

source /etc/environment
Make it take effect.

 

This command can also restore errors of inherent commands such as sudo. When you enter sudo, the prompt "xx is not in the path environment variable, so this command cannot be found" appears, if your/ext/environment has not been modified, you can use this command to fix it.

However, this is generally not recommended. If an error occurs, the sudo command of ubuntu cannot be executed.

Generally, the user environment variables are set:

 

gedit ~/.bashrc
Open the user environment variable configuration file, which can be opened without using the sudo command, because it is a user environment variable,

 

To the end, add the following sentence:

Export PATH = xx: $ PATH, where xx is the PATH you set. $ PATH is indispensable. If it is not formatted, sudo, apt-get, and other inherent commands cannot be executed.

For example, configure the adb command of Android to the user's environment variable.

Save and exit. Enter the following information on the terminal:

 

source ~/.bashrc
.

 

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.