1

I understand this type of question has been asked

Help me understand .profile, .bashrc, etc

Sequence of scripts sourced upon login

But I'm having a hard time understanding it.

I've got an Ubuntu machine setup so it connects to Jenkins as a slave. On this machine I've edited /etc/bash.bashrc and exported PATH with additional tools.

When I run a terminal (from the GUI) and execute

echo $PATH

I see the extra values on PATH.

When I run a sh script (from the GUI) which executes

echo $PATH

the extra values are missing.

If the same script is executed via "Startup Applications" the extra values are also missing from PATH.

Since I'm connecting to Jenkins using this approach that's a problem for me. i.e. It means my build jobs fail.

The only 'fix' I've found is to add the values to /etc/environment. When placed here the extra entries on the PATH appear in both scenarios.

But... only after the user logs back in/restarts. Which is not ideal.

How can I configure the machine so the extra entries are add to path for all scenarios?

FYI: I'm using Chef to configure the machine so it'll need to set these variables.

  • Why would you need to restart? I mean, yes, you do since that file is only read once when you log in, but from now on, it will be there every time you log in again, you don't need to do it each time. – terdon Oct 11 '16 at 16:53
  • After configuring the machine I'd normally run a build to verify it. I'd prefer not to have to logout and back in to run the build. Just an extra step to forget about which will cause problems. – Shane Gannon Oct 12 '16 at 16:03
  • Then just source the file manually once to check that it works: . /etc/environment – terdon Oct 12 '16 at 16:04
  • What do you mean by source the file? Load it manually? – Shane Gannon Oct 12 '16 at 16:15
  • No, I mean source it :). Just run the command I gave: . /etc/environment. The . is the source command. See askubuntu.com/a/601131/85695. Sourcing a file will make any variables set in it available in your current shell session. – terdon Oct 12 '16 at 16:18
2

Setting environment variables via /etc/bash.bashrc does not make them available in the graphical environment. I would suggest that you instead create the file /etc/profile.d/myvars.sh and set the variables from there. Files in the /etc/profile.d folder with the .sh extension are sourced by the display manager, and with that made available in the whole session, including the graphical environment.

Reference: EnvironmentVariables

  • Thanks Gunnar. That approach looks promising. I'll give it a try. – Shane Gannon Oct 12 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.