我有一个 Ubuntu 11.04 虚拟机,我想设置我的 Java 开发环境。我做了如下
sudo apt-get install openjdk-6-jdk
将以下条目添加到~/.bash_profile
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export PATH=$PATH:$JAVA_HOME/bin
Run Code Online (Sandbox Code Playgroud)保存更改并退出
再次打开终端并输入以下内容
echo $JAVA_HOME (blank)
echo $PATH (displayed, but not the JAVA_HOME value)
Run Code Online (Sandbox Code Playgroud)什么也没发生,就像 JAVA_HOME 的导出和它添加到 PATH 从未完成一样。
我不得不去~/.bashrc并在文件末尾添加以下条目
#Source bash_profile to set JAVA_HOME and add it to the PATH because for some reason is not being picked up
. ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
我.bash_profile
在我的/home/user
目录中找不到Ubuntu 14.04 。我用ls -a
命令查看了.bash_profile
,但没有这样的文件。
据说非登录shell的设置进入.bashrc
文件和登录shell设置进入.profile
文件。
登录和非登录 shell 的真正含义是什么?
请尽量不使用技术术语进行解释。
我是 Ubuntu 的新手。我正在运行 13.10 桌面版。
我想为 bash 设置一些系统范围的别名和自定义提示。我找到了这篇文章:
https://help.ubuntu.com/community/EnvironmentVariables
按照本文中的建议,我创建了 /etc/profile.d/profile_local.sh。它归 root 所有,并且与那里的其他脚本一样具有 644 的权限:
root@ubuntu:/etc/profile.d# ll
total 28
drwxr-xr-x 2 root root 4096 Mar 23 08:56 .
drwxr-xr-x 135 root root 12288 Mar 23 09:15 ..
-rw-r--r-- 1 root root 660 Oct 23 2012 bash_completion.sh
-rw-r--r-- 1 root root 3317 Mar 23 07:36 profile_local.sh
-rw-r--r-- 1 root root 1947 Nov 23 00:57 vte.sh
Run Code Online (Sandbox Code Playgroud)
我进一步确认 /etc/profile 调用 /etc/profile.d。它包含以下代码块:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if …
Run Code Online (Sandbox Code Playgroud) 我将如何使这个/media/De Soft/mongodb/bin
PATH 变量永久化?
每个人都在说“export PATH=$PATH:media/De\ Soft/mongodb/bin
对您的~/.profile
, 或.bashrc
, 或.zshenv
取决于您的外壳”。
我不知道什么是~/.profile
、 或.bashrc
、 或.zshenv
。他们实际上是做什么的?
我将如何添加export PATH=$PATH:my/path
到我的 .profile/.bashrc/.zshenv?
我正在使用带有默认终端的 64 位 Ubuntu 14.04 LTS。
刚刚安装了 Ubuntu 14.04.1 LTS。
根据.profile,
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash, if ~/.bash_profile or ~/.bash_login exists.
Run Code Online (Sandbox Code Playgroud)
没有 ~/.bash_profile 或 ~/.bash_login。
打开终端时似乎没有来源 .profile 。
我想将我所有的登录配置集中在我的~/.bash_profile
. ~/.bashrc
默认情况下有一个那里,但我用一个~/.bash_profile
.
但是,当我登录时,在~/.bash_profile
获取源之前的某些内容并显示以下内容:
Linux ubnt10-dev1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Ubuntu 10.04.4 LTS
Welcome to the Ubuntu Server!
* Documentation: http://www.ubuntu.com/server/doc
System information as of Fri May 9 12:17:39 EDT 2014
System load: 0.01 Processes: 74
Usage of /: 5.5% of 18.58GB Users logged in: 0
Memory usage: 4% IP address for eth0: 123.x.x.x
Swap usage: 0%
Graph this data and manage this system at https://landscape.canonical.com/
New …
Run Code Online (Sandbox Code Playgroud) 对于 11.04,我重新安装了我的系统。该安装的一部分是安装rvm,它rvm.sh
在/etc/profile.d/
. 这不起作用,因为/etc/profile
(加载每个 +r in /etc/profile.d/*.sh
)没有被加载。根据文档,该配置文件仅在登录时运行 bash 时才来源。为了验证这一点,我调用了bash --login
,之后rvm
就可用了。
这在没有任何配置的以前版本的 Ubuntu 中对我有用。也就是说,全新安装的 10.10 将正确获取 profile/.d。
我的问题是:我做错了什么,还是在 Natty 中做出的一些新假设破坏了这一点?我目前的解决方法是source /etc/profile
in ~/.bashrc
(这很糟糕,因为配置文件是在bashrc之前加载的,但可以解决问题)。
我很难理解什么属于~/.profile
以及什么属于~/.bashrc
。
根据我所读到的内容,在我看来,它~/.profile
应该用于环境变量以及~/.bashrc
别名、函数等。如果我将所有export
语句从~/.bashrc
移至~/.profile
,一切是否都会按预期进行,或者我是否会破坏某些内容?
(如果您想查看这两个文件,这是我的 dotfiles 存储库。)
编辑 2022-06-03:我已将大部分环境变量从~/.bashrc
移至~/.profile
,并向自己保证~/.bash_profile
来源~/.profile
. 我留下的唯一环境变量~/.bashrc
是那些仅在我在 shell 中工作时才重要的环境变量,例如,与 less、提示符、slrn 等相关的环境变量。一切似乎都进展顺利。谢谢您的帮助。
这些是~/.profile
我的 13.10 附带的股票内容(已删除注释行):
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Run Code Online (Sandbox Code Playgroud)
这是从 Debian 继承的,但为什么 Canonical 决定保留它?据我所知,这不是标准的 *nix 方式,我见过各种系统都没有发生这种情况,所以我认为他们一定有充分的理由这样做。这可能会导致在运行登录 shell 时出现意外行为(例如,当 ssh 进入机器时),而用户不希望有~/.bashrc
来源。
我能想到的唯一好处是不要将用户与许多启动文件混淆,并允许他们.bashrc
单独编辑并读取该文件,而不管 shell 类型。然而,这是一个可疑的好处,因为为登录和交互式 shell 设置不同的设置通常很有用,这会阻止您这样做。此外,登录 shell 通常不在图形环境中运行,这可能会导致错误、警告和问题(天哪!),具体取决于您在这些文件中设置的内容。
那么为什么 Ubuntu 会这样做,我错过了什么?