今天遇到一个问题,linux下某用户登陆后无法加在其自身的.bashrc, 通过source .bashrc发现.bashrc是没有问题的,文件的权限也是没有问题的。

后来发现是因为该用户下的~/.bash_profile不存在,其实加载顺序不是首先加载.bashrc,而是先加载~/.bash_profile。

将~/.bash_profile文件补一下就好了,执行:

vim ~/.bash_profile

 复制粘贴以下内容:

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

       . ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

然后

source ~/. bash_profile

上面问题解决了,

但是最后发现不是export 导入环境变量不自动生效问题,原因是:export语句写的太靠前了,没有放到~/.bashrc文件的最后边,导致被另一个同名但是不同版本的环境覆盖了,所以一直报错。然后把前面的另一个同名环境删除就行了。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐