βœ’οΈ
Start your developer blog today!
βœ‰οΈ
Questions?
Email me

How to Access Environment Variables in a Makefile

Mar 19, 2021 1 min read

How can we access environment variables inside our Makefile?

Suppose this is our project structure.

πŸ“‚ project
 ┣ πŸ“œ Makefile
 β”— πŸ“œ .env

Unfortunately, Makefile doesn’t automatically have access to the root .env file, which might look something like this.

# .env
HOSTNAME=localhost
PORT=3000

That said, we can include the appropriate environment file in our Makefile.

# Makefile
include .env
URI:=$(HOSTNAME):$(PORT)

The environment variables are then accessible using the $(VAR_NAME) syntax.


More CLI Articles