I have a .sh
file that locally sets some environment variables in my shell source my_env.sh
.
#!/bin/sh
echo "Setting up local environment variables"
export MY_URL="http://domain.com"
echo "Done"
This only sets the variables for that session. Which means that my Python Celery and Supervisor apps which run under a different session cannot access them. I understand I can run them under a user, but I want to know if on Ubuntu using the same shell script above if I can set the variables so they are globally accessible to all applications regardless of users or session?
export your variables in the "/etc/profile".
NOTE: This will make it global for each shell sessions for any user. If you wish to set this variable for every session for a specific user, set it in that user's "~/.profile".
If you are using bashrc or zshrc you can source the shell file which sets the environment variables across the sessions or precisely loads all the environment variables in each session.
The zshrc and bashrc is available in your $HOME directory. or ~/.zshrc and ~/.bashrc. The current shell can be looked via
Have a look at setting env permanently for adding it to the profile.
According to Ubuntu env variables doc the best way would be
That's assuming you don't mind having them set for the whole machine.