Linux Mint - 永久添加环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19013725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:55:45  来源:igfitidea点击:

Linux Mint - adding environment variables permanently

linuxbashenvironment-variableslinux-mint

提问by SalmonKiller

I was trying to modify the ~/.profile file to add a line to the PATH variable. I added this line:

我试图修改 ~/.profile 文件以向 PATH 变量添加一行。我添加了这一行:

PATH=$PATH:/home/paul/avatar-gf-1.0-ea/glassfish4/bin/

at the end. I restarted the terminal, but it still did not identify commands in that directory. Does anyone know what I am doing wrong?

在末尾。我重新启动了终端,但它仍然没有识别该目录中的命令。有谁知道我做错了什么?

采纳答案by oceanexplorer

Try this in the ~/.pam_environment in your home folder, if it does not exist then create it

在您的主文件夹中的 ~/.pam_environment 中尝试此操作,如果它不存在则创建它

PATH DEFAULT=${PATH}:/home/paul/avatar-gf-1.0-ea/glassfish4/bin/

You will need to log in and out.

您需要登录和退出。

回答by konsolebox

Run bash -xlto see which startup files are loaded with your shell. .profilemay actually not be read. Otherwise try adding exportto your assignment:

运行bash -xl以查看您的 shell 加载了哪些启动文件。.profile实际上可能不会被读取。否则,请尝试添加export到您的作业中:

export PATH=$PATH:/home/paul/avatar-gf-1.0-ea/glassfish4/bin/

Reference about bash's startup files: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

bash启动文件参考:https: //www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

回答by migueloop

if you edit .bashrc file:

如果您编辑 .bashrc 文件:

vim ~/.bashrc

you will see next line

你会看到下一行

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

So create a ~/.bash_aliases in your $HOME folder and add any command you want to be executed when you open the terminal

所以在你的 $HOME 文件夹中创建一个 ~/.bash_aliases 并添加任何你想在打开终端时执行的命令

回答by vzhemevko

I'm running Mint 18.3 Cinnamon. The changes in ~/.profile got picked up only after I logged out/in from the account. The terminal restart was not enough in my case.

我正在运行 Mint 18.3 Cinnamon。~/.profile 中的更改仅在我从帐户注销/登录后才被接收。在我的情况下,终端重启是不够的。

回答by Ajmal V Aliyar

You may add an entry to ~/.pam_environment

您可以向~/.pam_environment添加一个条目

  1. Use any editor to access the file. I am using the default LinuxMint Text Editor (xed).

    xed ~/.pam_environment

  2. That file is likely to have some entries already. Add a new line to the file and add your entry. For example, I am adding a java binary path which is in the optfolder to the $PATHenvironement variable :

    PATH DEFAULT=${PATH}:/opt/JDK11/jdk-11.0.2/bin

    Or if you want to add a path that is in the user home or something like that, then do like :

    PATH DEFAULT=${PATH}:/home/@{PAM_USER}/MyPrograms

  3. Save the file. It should work. If it doesn't, log out, log back in and try again. If it doesn't work even after that, then restart and try again and it will work for sure. :)

  1. 使用任何编辑器访问该文件。我正在使用默认的 LinuxMint 文本编辑器 (xed)。

    xed ~/.pam_environment

  2. 该文件可能已经有一些条目。在文件中添加一个新行并添加您的条目​​。例如,我将opt文件夹中的java 二进制路径添加到$PATH 环境变量:

    PATH DEFAULT=${PATH}:/opt/JDK11/jdk-11.0.2/bin

    或者,如果您想添加用户主页中的路径或类似的路径,请执行以下操作:

    PATH DEFAULT=${PATH}:/home/@{PAM_USER}/MyPrograms

  3. 保存文件。它应该工作。如果没有,请注销,重新登录并重试。如果在那之后它仍然不起作用,那么重新启动并重试,它肯定会起作用。:)