I have a requirement where I need to set a custom environment variable called CLUSTER_ENV = '#fooURL'
The steps I have followed are:
Open terminal, open bash_profile and save CLUSTER_ENV='#foo'. When I do echo $CLUSTER_ENV , I get blank output.
I did the same thing in the bashrc file and in this case, the $CLUSTER_ENV shows the value only when I run it in the same terminal window.
Which is the best or recommended way to permanently set the environment variable on a Mac?
Im running El Capitan.
I have gone through these links for reference:
http://osxdaily.com/2015/07/28/set-enviornment-variables-mac-os-x/
Mac OS X 10.9 - setting permanent environment variables
As you will normally do on any Linux distro: export CLUSTER_ENV=my.url.com which will have to be added to ~/.bash_profile
Related
I've not had success setting up an environment variable on El Capitan. Nothing to do with dock or bash shell. Trying to run a java gui which requires an environment path variable to a JDBC driver to connect to an oracle db:
http://docs.oracle.com/cd/E11882_01/install.112/e38228/inst_task.htm#BABBBHJH
I have tried methods:
in launchd.conf:
setenv JDBC /Users/mac_admin/Downloads/Oracle/instantclient_12_1
osx - Setting environment variables in OS X? - Stack Overflow
in .profile:
export JDBC /Users/mac_admin/Downloads/Oracle/instantclient_12_1
terminal - How do I set environment variables on OS X? - Ask Different
in .bash_profile:
export JDBC=$(/Users/mac_admin/Downloads/Oracle/instantclient_12_1)
Where to Set Environment Variables in Mac OS X
In each case, the export command at Terminal does not show the new variable.
What is correct method for El Capitan?
Is "JDBC" an acceptable name for the variable? Or am I supposed to label it PATH? I notice the export command already lists a PATH item, and I am afraid to overwrite it:
declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands"
Is /Users/mac_admin/Downloads/Oracle/instantclient_12_1 an acceptable location for the files?
thx
It kind-of matters where you want to use this. If you are just trying to get some binary utility to run from Terminal shells you launch add an export into ~/.bash_profile and you are good to go: export JDBC='Robert was here'
tcc-rkuhar:scouting robert.kuhar$ source ~/.bash_profile
tcc-rkuhar:scouting robert.kuhar$ echo $JDBC
Robert was here
You need the equals sign to get the environment variable set. Assuming that the value you've put in the export JDBC is a directly that has the binaries you want to execute. The line in your ~/.bash_profile is probably...
export JDBC=/Users/mac_admin/Downloads/Oracle/instantclient_12_1
PATH="${PATH}:$JDBC"
You'll know this worked if you
echo $PATH
/usr/local/bin:...blah...blah...blah::/Users/mac_admin/Downloads/Oracle/instantclient_12_1
What is the proper way to modify environment variables like PATH in Yosemite?
This is this question Setting environment variables in OS X? but specifically for yosemite since it doesn't work anymore.
Have you tried editing ~/.bash_profile?
Adding a line like this to bash_profile ought to do it:
export PATH=/usr/local/bin:$PATH
What shell are you using? I'm assuming you're using the default Bash shell. There's also Csh, Ksh, and Zsh.
The Terminal.app on Mac OS X by default starts a new login shell each time a window is open. This means that $HOME/.bash_profile or $HOME/profile is always executed when you open a new terminal window. You can set particular defaults in here. For example, I set PS1 and set -o vi.
NOTE: This may not be the case if you're using other Terminal apps like xterm. These open new terminal windows as just new shells. This means that you may not see the changes made in .bash_profile until you log out and log back in.
You can try editing $HOME/.bashrc and see if that helps.
What about other shells?
If you're using Kornshell (ksh), you need to edit the $HOME/profile and not $HOME/.bash_profile. If you're using Zshell (zsh), you're on your own. It's too wacky to describe here. Read the manpage for zsh and search for ZDOTDIR.
When you run a shell script, the $HOME/.bashrc is executed. Most people put something like this in their .bash_profile, so their .bashrc settings are included in a new terminal window:
[[ -x $HOME/.bashrc ]] && source "$HOME/.bashrc"
Some people set things they want to be set when they run a shell script, for example export $PS4="\$LINENO> ".
The $PATH is a bit different. You can set it in .bash_profile (I would not set it in .bashrc), But, Mac OS X has an automated why on how systemwide paths are set. A file called /etc/paths is used to set the default path for all users using either Bash or Kornshell via the /usr/libexec/path_helper program.
On my Mac, I set my $PATH to:
/usr/local/bin:/usr/share/bin:/bin:/usr/bin:/usr/sbin:/sbin:$HOME/bin
When I install programs, I usually install them under /opt when possible. Then, I link their binaries (where ever they're placed) to /usr/local/bin. This way, I don't have to keep building my PATH. Plus, it allows me to override system defaults. For example, /usr/bin/git is at 1.9.3. while my installed /usr/local/bin/git is at version 2.2.1.
One thing you should not do is modify /etc/profile because changes there may be replaced on OS X upgrades.
The problem is not with environment variables set and accessed from within /bin/bash or /bin/sh, but with envars that should be set for programs NOT executed from the shell; i.e. normal apps executed from the dock or Finder.
After finally getting things right with launchctl in Mavericks, Apple is in the process of changing things again. The useful subcommands of launchctl are now labelled as "legacy subcommands", some of which are no longer supported. That leaves a question mark over the others.
In any case, the most important subcommands are still available for now.
launchctl allows for the setting of the overall environment in which user processes execute. It appears that the overall user environment is inherited by all Terminal processes; i.e. all setenv variables are exported. It's a bit tricky to confirm that. In any case, you will still need your .profile and .bashrc to define functions and aliases, which are not supported by launchctl.
I go to some lengths to ensure that all of my launchctl vars are also defined in my profile. This enables me to set up the same environment on remote or VM linux systems, with a few minor tweaks.
Al of my setup is described in this blog post .
following solution worked for me.
Open Terminal
Click on Terminal Menu at right upper corner.
click on Preferences
Click on General
Change Shell open with to command and put /bin/bash in text box.
Now whatever configuration you do in ~/.bash_profile takes effect. Previously you were not using bash(were using ksh) that is why it was not reading .bash_profile.
I am using Scientific Linux 6.1. To run a program (DS9) I need to set this environment variable:
export XPA_METHOD=local
So I saved it in .bashrc and there is no problem when I run the program from the bash terminal. But when I run it in the GUI (for example by clicking on "Open with ds9" in nautilus), this variable is not recognized.
I would really appreciate if anyone could help me in setting the environment variable in GNOME.
Add it to ~/.profile instead of .bashrc
Edit: Log off and on again for the change to take effect.
I am trying to download myrna tool on mac os x.
for one of procedures on installation, "Set the MYRNA_HOME environment variable to point to the extracted directory (containing myrna_emr)"
So i tried this way
echo "export MYRNA_HOME=/.../....directory/.." >> ~/.bashrc
but it seems it does not work.(when i type echo MYRNA_HOME in command line, there is nothing OR when i type printenv MYRNA_HOME does not come out.)
anyone who knows how to set up Env Vars??
thank you,
There are several ways to do that. One would be adding your variable to ~/.bash_profile file.
Example:
MYRNA_HOME=/whatever/you/want/
export MYRNA_HOME
Then you can try if it works by logging in again and trying on a terminal:
$ echo $MYRNA_HOME
It should print whatever you set MRYNA_HOME to on ~/.bash_profile.
If you want the environment variable to be available to all users, you can change /etc/bashrc file. But I would prefer just changing one users' environment.
I'm using ant to build my project, and use the 'svnversion' executable to insert a version id into my sources for easy tracking of versions.
Running this ant file from the command line works, I've set my $PATH in .profile to include the path to svnversion and it works fine.
Now I try and run this same ant file from inside Eclipse and that does not work - the PATH in eclipse is set in another way than the PATH of the shell, I suspect this has to be set in a plist somewhere, but I don't know where.
Correct -- it's in the plist file
~/.MacOSX/environment.plist
This file actually contains key-value pairs for any environment variables you want to set, for the whole login session. Unlike .profile/.cshrc etc, it's available to GUI programs. Unfortunately, you can't access other environment variables (e.g., you can't use $HOME) or use any other programmatic constructs here.
Update: note that this is no longer supported under OS X 10.8 Mountain Lion, alas.
A quick search at developer.apple.com turned up Setting environment variables for user processes.
On Mac OS X El Capitan (10.11.5), this works for me for per-user PATH entries (and other environment variables, for that matter).
create a file $HOME/.profile
set all PATH related variables in that file
(if using bash), have your .bash_profile source that file, and .bashrc. This should be the entire contents of your .bash_profile:
# $HOME.bash_profile:
source $HOME/.profile
source $HOME/.bashrc
Near as I can tell, Mac OS does not source .bash_profile on login for PATH, presumably because that is often very slow to run (initializing bash completion etc). It does seem to read $HOME/.profile.
You still need a $HOME/.bash_profile to trigger bash to read $HOME/.bashrc, which it otherwise wouldn't do for interactive, non-login terminals as the ones created by Terminal.app.