2:02 AM
2
A: How to set environment variables to path so it can be read from GUI and command line from thesame program?

ZannaFirstly, note that if you want ~/.profile to be read, you'll need to remove ~/.bash_profile, otherwise ~/.profile will be ignored by Bash. You are actually overcomplicating this a bit. PATH is set in /etc/environment. It is always exported already, so it does not need to be exported again. If y...

 
I read that you can have .bash_profile and .profile because .bash_profile is only read when you start an interactive login session via CTRL+ALT+F1..F6. This means that when I log into the Gnome shell via GUI then .bash_profile is ignore.
I checked in etc/environment and the only variable it contains is: JAVA_HOME=/usr/local/java/jdk1.8.0_162/. This means that I need to declare export when defining environment variables in .profile but is doing this for every environment variable redundant? Instead can I just export PATH once after all the PATH variables? It wasn't clear to me until now that changes made to PATH in .profile are inherited by every shell. So when the terminal is opened it not only reads .bashrc but it can also see environment variables added in .profile even though it doesn't read .profile, right?
It wasn't clear to me until now that changes made to PATH in .profile are inherited by every shell. So when the terminal is opened it not only reads .bashrc but it can also see environment variables added in .profile even though it doesn't read .profile, right? If this is true then I can still use texlive via emacs even when I launch emacs from the terminal.
 
@MyWrathAcademia your system sounds pretty unusual. You should set PATHin °/etc/environment`, but it must be literal, no expansiond
 
And thanks for the link. I read it and it I knew about appending and prepending before. However I was under the impression that you needed both the colon and the list i.e. :$MANPATH inorder to append or prepend(in this case) the value to the PATH. I am basing this on the official textlive guide,3.4.1 Environment variables for Unix
 
@MyWrathAcademia yes, variables set in ~/.profile are available in every shell
@MyWrathAcademia what I said about prepending only applies to PATH. The other variables are unset by default and the path is dynamically determined (at runtime). The leading colon ensures that dynamic lookup still happens in addition to adding additional paths
@MyWrathAcademia well, Linux isn't Unix. You are using Ubuntu, right?
 
Thanks for confirming. What's unusual about my system? I have to admit I was shocked that my ~/etc/environment only had the JAVA_HOME variable without PATH. I added that when installing Java some months ago for a project and didn't have time to learn about environment variables properly until now.
 
2:02 AM
Is the file you're talking about /etc/environment or ~/etc/environment? Those are not the same place. Ubuntu has PATH in /etc/environment and ~/.profile with some code in it by default, and no ~/.bash_profile
Need to go AFK. Back later!
 
Your right, I mean /etc/environment. For your third comment if my understanding is correct you are saying that I only need $PATH which is the list since this PATH has already been set? For MANPATH and INFOPATH, the list is not needed since these two environment variables have never been set?
I will clean up my ~/.bashrc a bit on your recommendation. However should I leave the PATH set by anaconda? I don't know why anaconda automatically set this PATH after install. From looking at this PATH PATH="/home/Fedora_User/Anaconda3/bin:$PATH", do you think that this may be an alias? Since I can only launch it from the terminal typing anaconda-navigator? Or maybe it is not an alias but a PATH, afterall I can only launch the anaconda-navigator GUI from terminal. Thanks a lot for the rigor in your explanations. My understanding of environment variables and paths is lot more vivid now.
 
@MyWrathAcademia I am feeling my answer could have been a lot more thorough :) I even forgot the double quotes (fixed now) which aren't likely to be needed, but should still be included. The line you showed PATH="/home/Fedora_User/Anaconda3/bin:$PATH is not an alias (aliases start with alias), it prepends Anaconda's bin directory to your PATH so it is found before others. There is some justification for this being in ~/.bashrc, if ~/.profile does not source ~/.bashrc, because this adjustment to PATH may result in programs finding the wrong python and not working - this isn't an issue
... if the PATH is only adjusted in interactive shells. But in Ubuntu by default ~/.profile does source ~/.bashrc... Only Ubuntu is on topic here - if you're using fedora you should ask on Unix & Linux instead. My answer really assumes an Ubuntu environment and its defaults (of course, it's possible to configure your environment differently on Ubuntu) and we seem to be getting quite bogged down with stuff about your setup that's unexpected to me. You would get much more helpful answers over on U&L if you have a regular setup on a different distro as folks there will know about it!
 
Its very clear to me now. About what you mentioned about the correct path for MANPATH being dynamically determined. We need to start with a colon because there is no list. This is thesame way as appending variables to an empty list in Python which happens here because MANPATH has not been set. This is my understanding of how the path being determined dynamically works and why we need to append the value and not prepend in such a case when $MANPATH is empty.
Can you clarify what you mentioned about the justification for PATH="/home/Fedora_User/Anaconda3/bin:$PATH being in bashrc. I think I already had Python 2 installed before installing Anaconda which came with Anaconda 3. When you say "this isn't an issue", do you mean that I should leave PATH="/home/Fedora_User/Anaconda3/bin:$PATH in bashrc where it was automatically added by the program? I think that as long as I create thesame path ifor Anaconda in .profile it should be read unless the Anaconda program only reads bashrc.
 
sorry I ran out of characters mid sentence... it's not an issue (or it's less of an issue) to have Anaconda put its own Python first in your PATH if only interactive shells have that PATH. Adjustments to PATH in ~/.profile affect all programs (because it's run when the user logs into their session) but in ~/.bashrc, theoretically, they only affect interactive shells. But in Ubuntu by default ~/.profile sources ~/.bashrc so whatever ~/.bashrc does affects everything
 
I see, I think I will move the Anaconda path to .profile although there must have been a good reason why the program added it there automatically. My distro is fedora but from what I have read it seems that the desktop environment carries a lot more weight when defining environment variables, I might be wrong on this though. The differences in fedora and ubuntu on this topic are minor, e.g. which files are available (.pam_environment and .profile for Ubuntu and bash_profile for fedora). For Besides I think the most important thing is that I use Gnome.
There is an interesting article here environment.d about another way of setting environment variables in files like ~/.config/environment.d/my.conf but my system doesn't have environment.d.
Another thing, after re-naming ~/.bash_profile to ~/.profile if I ever wanted to use an interactive login shell then how would I be able to load environment variables?
 
2:02 AM
Clearly, everything is different between Ubuntu and Fedora w/r/t/ setting environment variables! You have different config files entirely. For all I know, MANPATH and INFOPATH are set so you shouldn't overwrite them in the way I suggested. I wouldn't recommend renaming ~/.bash_profile since I don't know what it's expected to have in it :( Please ask your question on Unix & Linux instead!
 
Please look at this: bugzilla.gnome.org/show_bug.cgi?id=736660. Start reading from about comment #51 and pay attention to comment #54. It seems that Gnome Wayland does not load .profile when a user logs in, that is, it is a non-login shell.
Understood. Just to mention env | grep MANPATH and env | grep INFOPATH returns null.
 
Thanks, I really don't want to mislead you... The bug thread is pretty interesting! So much stuff I don't know about what files get read when a graphical shell starts. I wonder where your PATH is initially set (since it's not /etc/environment). Ubuntu 18.04 is using X.org again, I guess because there were too many issues with Wayland on 17.10 to put it into LTS yet
 
I have a question. If I wanted to create a .conf file in the path: ~/.config/environment.d/my.conf. but the directory environment.d doesn't exist in my .config directory. In order to create the .conf file, can I just create the environment.d directory first? The .conf file will contain environment variables so I wanted to know if they can be seen by Gnome Wayland inside a directory that was created artificially by me and not the system.
 
@MyWrathAcademia if the program in question is configured to look there, they will look there whether you or some other process created the directory. But, I don't know whether it will work, because I don't know whether any program has been configured to look there to find config files. Sorry not to be more helpful!
 
That was actually very helpful. Systemd has been configured to look exactly there.