I've just come across a way to persist env variables after reboot with a simple command.
Following these steps assuming you have a .env
file with the following content located in your home directory:
MY_NAME=John
MY_PASSWORD=123456
- Log into the machine and open the
.bash_profile
file. - Add the following line in the end of the file, replacing
joshua
with your own username:
set -o allexport; source /home/joshua/.env; set +o allexport
- Save and exit the file.
- Log out and log in again.
- To verify that the environment variables have been persisted, run the following command in the console:
printenv
This should print out the environment variables that you set in the .env
file.