Ubuntu PROFILE-ENVIRONMENT-BASHRC Add Environment variables

Source: Internet
Author: User

Ubuntu Linux System environment variable configuration file:

/etc/profile: The first file that is used when the operating system customizes the user environment at logon, which sets the environment information for each user of the system, which is executed when the user logs on for the first time.

/etc/environment: The second file used by the operating system at logon, the system sets environment variables for environment files before reading your own profile.

~/.profile: The third file that is used to log on is the. profile file, which each user can use to enter shell information that is specific to their own use, which is executed only once when the user logs on. By default, he sets some environment variables, Executes the user's. bashrc file.

/ETC/BASHRC: Executes this file for each user running the bash shell. When the bash shell is opened, the file is read.

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

Pash How to set environment variables:

Method One: Use the. Profile or. bashrc file in the home directory (recommended)

Log in to your user (non-root) and enter in the terminal:

$ sudo gedit ~/.profile (or. bashrc)

The following settings can be added to the path at the end of this file:

Export path= "$PATH: Your path1:your path2 ..."

Save the file, log off and log in, and the variable takes effect.

Variables added in this way are valid only for the current user.

Method Two: The profile file under the system directory (caution)

In the system's etc directory, there is a profile file that edits the file:

$ sudo gedit/etc/profile

The following settings are added to the path at the end:

Export path= "$PATH: Your path1:your path2 ..."

After the file edits are saved, the system restarts and the variables take effect.

The variables added in this way are valid for all users.

Method Three: Environment file under the system directory (caution)

In the system's etc directory, there is a environment file that edits the file:

$ sudo gedit/etc/environment

Locate the following PATH variable:

Path= "<......>"

Modify the path variable to include your own path, for example:

Path= "<......>:your path1:your path2 ..."

Each path is separated by a colon. The file is also restarted to take effect, affecting all users.

Note that this is not the add export path= ....

Method Four: Enter directly under the terminal

$ sudo export path= "$PATH: Your path1:your path2 ..."

This way the variable takes effect immediately, but the setting becomes invalid after the user logs off or the system restarts, and is appropriate for the temporary variable.

Note: Changes to methods two and three need to be cautious, especially if the root user modifies the error, which can cause some serious system errors. So I recommend using the first method. In addition, the development of embedded Linux is best not done under root (unless you are very familiar with Linux!!) ) to avoid serious system errors caused by improper operation.

The following is an example of a problem caused by error modification of a environment file and a workaround:

Problem: Unable to log on due to accidentally setting environment variable in etc/environment

Tip: Do not set export path in etc/environment this will cause the system to log on after a reboot

Workaround:

In the login interface alt +CTRL+F1 into command mode, if not the root user needs to type (root user not so verbose, gedit edit will not be displayed)

/usr/bin/sudo/usr/bin/vi/etc/environment

The cursor moves to the export path** line, and the row is deleted consecutively by D two times;

Input: Wq save exit;

Then type/sbin/reboot reboot system (may prompt need to boot, this time direct power off)

Transferred from: http://my.oschina.net/qinlinwang/blog/30471

Individuals have recently used more for ~/.profile

sudo gedit ~/.profile

Then add: Export path= "$PATH: Mtpath"

Reboot the system to

The full path runs the program when there is no environment variable to start the effect.

View environment variables: Echo $PATH

Ubuntu PROFILE-ENVIRONMENT-BASHRC Add Environment variables

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.