export APP_ENV=production to the end of ~/.bashrc, then run source ~/.bashrc (or log in again). For all users, add APP_ENV=production (without export) to /etc/environment. Check it with echo $APP_ENV or printenv APP_ENV.
Before you start
- Connect with SSH.
- An environment variable is a named value that programs can read, such as
PATH(where the shell looks for commands) orHOME(your home folder). Apps often read settings such as API keys orNODE_ENVthis way. - These steps are for the
bashshell, the default on Ubuntu, Debian, AlmaLinux and Rocky Linux. Check yours withecho $SHELL.
How to set a variable for the current session
export, only the shell itself sees it, not the programs it starts.
To remove it: unset APP_ENV.
How to set an environment variable permanently
- For your user (~/.bashrc)
- For all users (/etc/environment)
- For all users (script)
1
Open .bashrc
2
Add the variable at the end
export GREETING="hello world".3
Load it
Which file should I use?
If both
~/.bash_profile and ~/.profile exist, bash reads only ~/.bash_profile at login. On AlmaLinux and Rocky, ~/.bash_profile loads ~/.bashrc, so ~/.bashrc works for both.
How to set variables for services and cron jobs
~/.bashrc is not read by systemd services or cron jobs. Set variables there instead:
- systemd service: add
Environment=APP_ENV=productionorEnvironmentFile=/opt/myapp/.envto the[Service]section, thensudo systemctl daemon-reloadand restart. See create a systemd service. - cron: put
APP_ENV=productionon its own line at the top of the crontab (crontab -e), or set it inside the script. See schedule tasks with cron. - sudo: sudo resets most variables for safety. Pass one on purpose with
sudo APP_ENV=production commandif your sudo policy allows it.
How to check it worked
Open a new SSH session and run:printenv prints the value, or nothing if the variable isn’t set. To see all variables, run printenv or env.
If a broken .bashrc stops you logging in normally, connect with ssh -t alex@203.0.113.10 bash --norc and fix the file, or use the VNC console.
Frequently asked questions
How do I add a folder to PATH permanently?
Addexport PATH="$HOME/bin:$PATH" to ~/.bashrc and run source ~/.bashrc. Put the new folder first to override system commands, or last ($PATH:$HOME/bin) to only add new ones.
Why is my variable empty in a new terminal?
You set it withexport only in the old session, or you added it to a file that this kind of shell doesn’t read. Use ~/.bashrc for your user, and log in again after changing /etc/environment.
What is the difference between env and printenv?
Both list environment variables. printenv NAME prints one value. env NAME=value command runs a single command with an extra variable.
Can I use a .env file?
Yes. Many apps read.env themselves. To load one into your shell, run set -a; source .env; set +a. For services, use EnvironmentFile= in the systemd unit.
Related guides
VPS and dedicated server guides
Every server guide in one place.
Edit files with nano and vim
Change .bashrc safely.
Create a systemd service
Environment for services.
Schedule tasks with cron
Environment for cron jobs.
Checked against the official GNU Bash Reference Manual: Bash Startup Files and the
pam_env documentation on 4 November 2026; commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions, shells or releases.Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026