Setting environment variable globally without restarting Ubuntu

前端 未结 3 1988
暗喜
暗喜 2021-01-30 11:37

I know that system wide environment variables can be set by adding entries into

/etc/environment

or

/etc/profile
3条回答
  •  走了就别回头了
    2021-01-30 12:02

    I fear the solution here is a frustrating one: Don't use environment variables. Instead use a file.

    So, instead of setting up /etc/environment with:

    SPECIAL_VAR='some/path/I/want/later/'
    

    And calling it with:

    $SPECIAL_VAR
    

    Instead, create a file at ~/.yourvars with the content:

    SPECIAL_VAR='some/path/I/want/later/'
    

    And source the thing every time you need the variable:

    cd `source ~/.yourvars; echo $SPECIAL_VAR`
    

    A hack? Perhaps. But it works.

提交回复
热议问题