Beginner Topic 6 of 50 DevOps & Tooling
Environment Variables
Named values configuring processes.
How it works
Environment variables are named string values attached to a process and inherited by the processes it starts. They are set with export in a shell, with a .env file loaded by a tool, or by the container or service manager, and read through the language runtime, for example process.env or os.environ. Common ones include PATH, which lists directories searched for commands, HOME, USER and LANG. Changing a variable in a child process does not affect its parent. Shell startup files such as .bashrc and .profile set them for each session.
Where it is used
Applications use them to switch between development, staging and production, to pass database URLs, ports and feature settings, and to inject credentials without hard-coding them, as the twelve-factor approach recommends.
Common pitfall
Committing .env files with secrets, printing the environment into logs and assuming a variable is set cause leaks and crashes. Variables set in one terminal are not visible to a service or cron job. Validate required variables at startup and keep secrets in a secrets manager.
Where it fits in the course
Environment Variables is topic 6 of 50 in DevOps & Tooling, rated Beginner. It follows Package Managers. The next topic is Git Basics.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the DevOps & Tooling quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the DevOps & Tooling quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Environment Variables?
Where do people use Environment Variables?
What is the most common mistake with Environment Variables?
What should I learn before this topic?
How can I practice it?
Is Environment Variables hard to learn?
How long does it take to learn Environment Variables?
Which topics are related to Environment Variables?
What should I study after Environment Variables?
Related topics
- Package Managers (DevOps & Tooling)
- Git Basics (DevOps & Tooling)
- Text Editors and IDEs (DevOps & Tooling)
- Branching and Merging (DevOps & Tooling)
- Variables (Programming Fundamentals)
- Condition Variables (Concurrency & Parallelism)
- Random Variables (Math for Computing)