Linux Mint - adding environment variables permanently [closed]

 ̄綄美尐妖づ 提交于 2021-02-06 01:44:27

问题


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

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?


回答1:


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

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

You will need to log in and out.




回答2:


Run bash -xl to see which startup files are loaded with your shell. .profile may actually not be read. Otherwise try adding export to your assignment:

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

Reference about Bash's startup files: Bash Startup Files




回答3:


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




回答4:


If you edit the .bashrc file,

vim ~/.bashrc

you will see the 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 file in your $HOME folder and add any command you want to be executed when you open the terminal.




回答5:


You may add an entry to the ~/.pam_environment file.

  1. Use any editor to access the file. I am using the default Linux Mint 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 opt folder to the $PATH environment 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. :)



来源:https://stackoverflow.com/questions/19013725/linux-mint-adding-environment-variables-permanently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!