hyper-v ubuntu 对 ~/.profile 的更改即使在 logout/login 之后也不会生效

hyper-v ubuntu changes to ~/.profile do not take effect even after logout/login

我使用快速创建在 hyper-v 上安装了 ubuntu 18.04。

我正在尝试设置一个每次登录都会生效的环境变量。

我放了下面一行:

export BOOST_ROOT=$HOME/boost_1_69_0

在每个:

~/.profile
~/.bash_profile (did not exist by default)

一次一个,然后注销和登录。

然后我打开了一个新终端并发出:

echo $BOOST_ROOT

输出是一个空行。我做错了什么?

如果我把它放在 ~/.bashrc 它会生效,但是据我了解,这仅适用于新的 bash 终端,不会对任何不生效的终端生效在 bash 中 运行,对吗?

我问是因为 gnome-terminal 有一个选项(在右键单击 -> 首选项中)将 shell 视为登录 shell。 如果你不想弄乱它,你可以在 ~/.profile 中这样做(一定要删除 ~/.bash_profile):

# if running bash
if [ -n "$BASH_VERSION" ]
then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]
    then
        . "$HOME/.bashrc"
    fi
fi

这就是我的 Linux Mint 发行版所做的(并且 ~/.bashrc 所包含的不只是这个)。