Modifying environment variables for Linux

Source: Internet
Author: User

There are two common ways to modify environment variables:

    1. Temporary settings
      For example, we have just installed the Golang to add the goroot to the environment variable: export PATH=$PATH:/usr/lib/go-1.9 . If the original environment variable is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin , the export environment variable after executing the command will become: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/lib/go-1.9 . All we do is export PATH=$PATH:/usr/lib/go-1.9 equivalent to:
$PATH = "/usr/local/sbin:/usr......"$GOROOT = "/usr/lib/go-1.9"$PATH = $PATH + $GOROOT

How to view modified environment variables with commands:
echo $PATHOrenv

    1. Permanent settings
      Locate profile the file, and then edit it:
vi /etc/profile#添加以下内容export GOROOT=/usr/lib/go-1.9export GOBIN=$GOROOT/binexport GOAPTH=$GOROOT/srcexport GO_WORK_PATH=/home/workspace/go #自定义的工作空间#前面只是定义了变量,最后一句是关键export PATH=$PATH:$GOROOT:$GOBIN:$GOPATH:$GO_WORK_PATH

To take effect immediately, it is necessary to implement:
source /ect/profile
Restarting and reboot then echo $PATH discovering the environment variables was set before we restarted, and did not fail because of a reboot.

However , sometimes you will find that the environment variables and our settings are completely non-line after rebooting. This time, you need to find the .bashrc file:

vi ~/.bashrc#发现最下面有以下几行:export GOROOT=/home/libexport GOBIN=$GOROOT/binexport GOAPTH=$GOROOT/src

The original is because the settings in the .bashrc file "overwrite" our profile settings in the, OK, we now comment (delete) These lines, restart. The environment variables we set are finally in effect.

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.