This is the code I have currently in my provision.sh file for vagrant to run when setting up my VM: (I do have other code before this to install packages etc, it is all working, it's just that this environment variable is not being created and set)
#Add DB_HOST env variable
export DB_HOST=192.168.10.150:27017/posts
echo "DB_HOST=192.168.10.150:27017/posts" >> ~/.bashrc
source ~/.bashrc
Is there something massively wrong with this? Or is there some other method that I have to use?
Thank you to KamilCuk for helping me with this.
He told me to echo
into the /etc/environment
file, and add the DB_HOST env variable in there to make it persistent.
I did have some issues doing this and here is the command I used to make it work > echo "DB_HOST=[db-ip]" | sudo tee -a /etc/environment
So, echo
the variable name and its value, then pipe that into a tee
command, which basically just opens a file and allows write access (I think). You need to do it in this way because you need root user permissions to open and write to the /etc/environment
file, and you don't need to use sudo in order to complete the echo
.