4 Options to Create Environment Variables on *nix Machines
Setting ENVs on macOS and other *nix Systems

Full Stack Data Dev.
Search for a command to run...
Setting ENVs on macOS and other *nix Systems

Full Stack Data Dev.
No comments yet. Be the first to comment.
Simple API Lockdown Introduction The previous article reviewed how to set and read environment variables. We'll use that knowledge and set up an API Key as an environment variable for authorization in a .NET Web API Project. Keys are a variable you w...

Creating and Reading ENVs

Introduction This article is the start of a series on how to build an API using the .NET Framework. I'm sticking with .NET 6, it is the latest Long-Term-Support (LTS) Version. I'll be using Visual Studio for Mac as my IDE. Before you start yelling, ...

Introduction This article will setup a basic Hello World FastAPI project running in Docker. The purpose is to start off small before starting on a full real world project. What and Why Docker is a containerization platform. Docker combines applica...

Introduction This article will continue our journey and connect a FastAPI project to a SQL Server database. We'll walk through a full CRUD (Create, Read, Update, Delete) example of saving data through our FastAPI project to a database. We'll work ...

This article is meant as a reminder on how to set up and read environment variables for development.
Python Program Invocation. This option allows for variables to live for the duration of your program. This works when starting any Python program regardless of the operating system.
# Startup with env variables during program invocation
SOME_KEY="qwerty123" SOME_PORT="99999" myPythonApp.py
Set via terminal with the EXPORT command. Environment variables created in your terminal are saved to your terminals session. They only exist for the duration of your terminal window, once closed they are gone and are not available across multiple terminal windows.
The screenshot below shows an example of a newly created environment variable SOME_TEXT_VAR created in one session that is not available in another.

Using a .env file in development project.
Add a dot env file to your project to store variables for your project. Depending on your project you can read in the environment variables in different ways specific to your project.

Create permanent environment variables by modifying your Bash or ZSH (Z) Shell Profiles. Based on whatever terminal you use, open the following (macOS) ~/.bash-profile (bash) or ~/.zshrc (ZSH) file in order to create permanent environment variables. You can open those files in nano, vi, or whatever text editor of your liking. The # is a comment indicator. The example below is shown using the ZSH shell in my terminal.

From your terminal, you can print out a single environment variable at a time or all of them at once.
echo $VAR_NAME
# terminal print single variable
printenv
# print all system environment variables
These are helpful reminders when setting up and accessing environment variables for development.