Environment variables set in ~/.profile not persisted after login

I see.

Instead of ~/.profile, try ~/.zshrc instead; or ~/.bash_profile.

If I recall, the difference between ~/.zshrc and ~/.bash_profile is that ~/.bash_profile is executed at every login session, and ~/.zshrc only when a shell is initialised.

Please, try to confirm this as I’m not 100% certain. That said, a few tests of the theory should suffice.

Cheers.

You might also consider switching to bash as the default shell. There are a few guides for this somewhere.

I need my variables set before I open any terminal, so files such as ~/.zshrc wont help me, as indeed they run whenever you open a terminal.

I think ~/.bash_profile would run at login if you are using bash as your shell, which I’m not.

I originally thought the problem was that ~/.profile was not being run at login, but I’ve since verified that it is being run, but the particular setting I’ve added in are not being persisted. I’ll update the name of my other thread accordingly.

I’m pretty sure I had this working but it broke again. It broke after I install Flatpak, I think.

I use KDE (currently with ZSH but my default is BASH) and don’t have a ~/.profile at all. My assumption was that ~/.profile would be effectively the same as ~/.bash_profile.

Perhaps that was a wrong assumption if indeed variables contained within it are not being made available.

As the original thread remains open it might have been best to keep this contained there. Let’s see if any @Moderators consider it worth moving some of these posts.


Hi @toby1kenobi and welcome to the Manjaro community.

As a new forum user, please take some time to familiarise yourself with Forum requirements; in particular, the many ways to use the forum to your benefit:

To that end, some or all of these links may be invaluable:

Last, but not least, the Update Announcements, which you should check frequently for important update related information.

An issue may be directly related to a particular update; these announcements should generally be checked before posting a request for support.

I hope this is helpful.

Cheers.

What you are looking for is setting the environment.

The recommended method is to create the folder ~/.config/environment.d and inside that folder create a configuration file with your variables.

mkdir ~/.config/enviroment.d

continuing your example

echo TEST=testing > ~/.config/environment.d/testing.conf

This will work across desktops, pty and tty for your username - remember to reload userspace - either logout

systemctl soft-reboot
2 Likes

@linux-aarhus thank you. That seems to have worked

@soundofthunder you’re right I should have stayed on the original thread. I started a new one because I genuinely believed I had found a different issue while I was trying to fix the first one, but it was just my misunderstanding about export

1 Like

I’ve solved my problem by following this suggestion to use ~/.config/environment.d/something.conf
https://forum.manjaro.org/t/shell-export-not-working-as-expected/170548/9?u=toby1kenobi

However, it doesn’t end my confusion about why it doesn’t work in .profile. I suspect that a script from the installation of Flatpack is clobbering the values already in the environment variable.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.