So if you want to add an Environment Variable you could do a number of things:
- Edit
/etc/enviroment
(All Users)
- Edit
/etc/profile
(All Users)
- Edit
~/.bashrc
(Just You)
Editing any of the files above will ensure that any time you startup your machine, your environment will have access to those variables.
You could also edit my-service
or a file that my-service
includes (as suggested by Cyrus). This means that if you have write access to the source code for the my-service
program or a file that my-service
includes (calls before it's own execution), you could add a line to that file.
You also don't even have to edit a file! Whenever you launch a terminal you can make live changes to the environment simply by entering the text you would have added to one of the files mentioned above as a command. This environment change will be just like the ~/.bashrc
change, in that it will only work for the current user. If you plan to sudo <command>
, you will have to first sudo su
to switch to the super-user user, and then change the environment.
Weather you are editing a file or entering a command, I suggest using the following line of code. The export
command will ensure that environment variable is accessible by my-service
.
export ENV_VAR=value
Related question