Skip to content
/ vienv Public

A utility to set global environment variables on macOS, for both terminal and GUI apps.

Notifications You must be signed in to change notification settings

dlejay/vienv

Repository files navigation

vienv

vienv is a terminal utility that sets environment variables for both terminal and GUI apps on macOS.

It assumes your shell is zsh.

Install

Copy and paste in a terminal the following command

curl -sL https://raw.githubusercontent.com/dlejay/vienv/trunk/install.sh | sh
source ${ZDOTDIR:-$HOME}/.zshrc

A list of variables is installed with vienv. Run vienv after installation to change that list to your needs.

Usage

Edit the list of variables using

vienv

and add environment variables in the fashion

VARIABLE=/whatever/you/want

Apps need to be restarted after setting the variables.

Apps that auto-launch at login will also fail to get the new variables.

Setting your PATH

vienv uses launchctl setenv to set the environment variables; it is not the right tool to set your PATH for all GUI apps.

As scriptingosx.com says:

On macOS, system wide changes to the PATH should be done by adding files to /etc/paths.d.

or use .zprofile for a local change without sudo. I do not know a way to set the PATH also for GUI apps.

Uninstall

Step 1

Copy and paste in a terminal the following command

curl -sL https://raw.githubusercontent.com/dlejay/vienv/trunk/uninstall.sh | sh

Step 2

Remove vienv() from your .zshrc.

Background

There are several places where one can define environment variables.

  • For interactive use in a terminal, .zshrc is a good place;
  • For non-interactive terminal use, .zprofile is the canonical place. Variables set in .zprofile can also be used by certain GUI apps like MacVim;
  • But for other GUI apps this is not enough.

In the case of general GUI apps, it has become very difficult to get them access environment variables; the canonical method has changed over the years (cf. superuser, developer.apple, apple.stackexchange).

vienv uses the last method known to work (cf. Ted Toal, EnvPane, Machina Spectulatrix): read a user file environment.txt containing the list of variables to be set and then use launchctl setenv on each element of that list. The method is then made automatic by writing those instructions in a file ~/Library/LaunchAgents/environment.plist that shall be read and executed at each user login.

Alternative

EnvPane is a nice GUI app doing exactly the same things as vienv. It needs to install ~/.MacOSX/environment.plist, which is a problem when your $HOME is not writable.

About

A utility to set global environment variables on macOS, for both terminal and GUI apps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages