• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

AppleToolBox

Tools and Fixes for Mac, iPad, iPhone & iWatch

Search posts

  • About
  • Contact

CONNECT WITH US

CATEGORIES

  • iPhone
  • iPad
  • iPod
  • Apple Watch
  • Mac/MacBook
  • AirPods
  • Apple TV
  • News
  • Apple Services
  • HomePod
  • Reviews

SITE

  • Home
  • About Us
  • Contact
  • Advertise

Search posts

You are here: Home / Mac / macOS: How to Set Environment Variable

macOS: How to Set Environment Variable

By Michelle Honeyager 0 comments Last updated September 14, 2022

On the Mac, environmental variables store information, like who the current user is, default paths to commands and the name of the host computer. If you find yourself needing to create new environment variables, below we’ll cover the command lines in Terminal to set the value of the variables.

Opening Terminal

To start, open Terminal. You can go in through Go > Utilities > Terminal:

You can also open the Terminal through Spotlight. Hit the Command key and then the space bar at the same time to open Spotlight. Type Terminal and hit enter for Terminal to open.

Commands for Setting Environment Variables

You can create environment variables to control the behavior of a command. Apple’s support page states that this does not modify the command itself. Apple gives an example of using an environmental variable to set up a command print debug.

Apple states, “To set the value of an environment variable, use the appropriate shell command to associate a variable name with a value.”

For example, Apple gives the following command to set the variable PATH to a value:

% PATH=/bin:/sbin:/user/bin:/user/sbin:/system/Library/ export PATH

Here, the value would be /bin:/sbin:/user/bin:/user/sbin:/system/Library/

Adding “% PATH=” before the value and “export PATH” after the value sets the variable PATH.

According to Apple, this command can help you view all environmental variables:

% env

Variables set in any individual Terminal window are not available after you close that window. If you want to keep the variable, you have to set up a shell startup script. You can find information for how to do this on the zsh man page under Invocation. The Apple support page has a link at the bottom of the page that opens the man page in your Terminal.

Related Posts:

  • The Best iPhone And Mac Shortcuts For Beginners
    The Best iPhone And Mac Shortcuts For Beginners
  • iOS 13 or iPadOS problems and how to fix them - Troubleshooting Guide
    iOS 13 or iPadOS problems and how to fix them -…
  • Mac Tips For New Users In 2023
    Mac Tips For New Users In 2023
  • It Costs a Lot of Money to Repair an iPhone 12
    It Costs a Lot of Money to Repair an iPhone 12
  • How To Start Using Regex With The Shortcuts App
    How To Start Using Regex With The Shortcuts App
  • How To Use The Mac Terminal: The Basics
    How To Use The Mac Terminal: The Basics
  • How To Run Linux On Mac: A Step-by-Step Guide
    How To Run Linux On Mac: A Step-by-Step Guide
  • AirPods Pro---The Complete Guide
    AirPods Pro---The Complete Guide
  • Should I sign up for Apple’s iPhone Upgrade Program?
    Should I sign up for Apple’s iPhone Upgrade Program?

Reader Interactions

Write a Comment Cancel reply

Primary Sidebar

Recent Posts

  • Final Cut Pro and Logic Pro for iPad: What You Need To Know
  • Fix: System Has Run Out of Application Memory on Mac
  • iOS 16 Troubleshooting Guide: Common Problems And How To Fix Them
  • How to Fix iPhone Stuck on Do Not Disturb: 8 Best Fixes
  • Rapid Security Response: What It Is and How to Download It
  • What Happened to the Facebook Messenger App on Apple Watch?

Connect with us

Footer

ABOUT

  • About Us
  • Contact us
  • Advertise
  • Privacy
  • Terms of Use

GUIDES

  • iOS 13 & iPadOS
  • Apple ID
  • iCloud
  • App Store
  • iTunes
  • FaceTime
  • iMessage
  • Siri
  • Books and iBooks
  • Game Center
  • AirPlay

CONNECT

  • Facebook
  • Twitter
  • FeedBurner
  • YouTube

© Copyright 2010-2023 Guiding Tech Media · All Rights Reserved

This site and its content are in no way affiliated or endorsed by Apple, Inc. · Reproduction without explicit permission is prohibited