# Ubuntu中修改PATH环境变量

**URL:** <https://eijil.com/t/ubuntu-path/356>\
**Category:** 其它\
**Created:** [May 21, 2022, 12:19pm UTC](https://eijil.com/t/ubuntu-path/356 "2022-05-21T12:19:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tristan](https://eijil.com/user_avatar/eijil.com/tristan/32/986_2.png) [@Tristan](https://eijil.com/u/Tristan)\
**Post date:** [May 21, 2022, 12:19pm UTC](https://eijil.com/t/ubuntu-path/356/1 "2022-05-21T12:19:29Z")

</div>

如何改变PATH

a.直接修改$PATH值：

echo $PATH //查看当前PATH的配置路径

export PATH=$PATH:/xxx/xxx //将需配置路径加入$PATH 等号两边一定不能有空格

//配置完后可以通过第一句命令查看配置结果。

生效方法：立即生效

有效期限：临时改变，只能在当前的终端窗口中有效，当前窗口关闭后就会恢复原有的path配置

用户局限：仅对当前用户

b.通过修改.bashrc文件：(.bashrc文件在根目录下)

vi .bashrc // 编辑.bashrc文件

//在最后一行添上：

export PATH=$PATH:/xxx/xxx ///xxx/xxx位需要加入的环境变量地址 等号两边没空格

生效方法：（有以下两种）

…关闭当前终端窗口，重新打开一个新终端窗口就能生效

…输入“source .bashrc”命令，立即生效

有效期限：永久有效

用户局限：仅对当前用户

c.通过修改profile文件：（profile文件在/etc目录下）

vi /etc/profile //编辑profile文件

//在最后一行添上：

export PATH=$PATH:/xxx/xxx

生效方法：系统重启

有效期限：永久有效

用户局限：对所有用户

d.通过修改environment文件：（environment文件在/etc目录下）

vi /etc/profile //编辑profile文件

在PATH=/·········中加入“:/xxx/xxx”

生效方法：系统重启

有效期限：永久有效

用户局限：对所有用户
