setenv equivalent on mac?
Asked Answered
A

3

18

I want to set an environment variable using setenv:

setenv NODE_ENV localhost  

But setenv gives me an error saying the command is not found. Does anyone know how to perform the MAC OSX equivalent of setenv? Thanks!

Agio answered 24/9, 2013 at 18:18 Comment(3)
How is node.js relevant to your question?Pellikka
@KeithThompson - The question is obviously not about node (of course he is doing this to get node working but the answer to the question is independent of node); the OP is looking to set an environment variable and node is just the example. I am going to edit the question.Uranyl
@Howiecamp: The OP used the "node.js" tag. The question certainly doesn't look like it's really about node.js, but as far as I knew there could have been some connection that I was missing. The expected answer is that it's not relevant, but I was hoping that the OP would respond.Pellikka
V
35

you want export

NODE_ENV=localhost
export NODE_ENV

or on 1 line export NODE_ENV=localhost

and this has nothing to do with OSX per se, more to do with bash vs (t)csh as your shell

Vilipend answered 24/9, 2013 at 18:20 Comment(0)
V
8

Best for Mac is:

launchctl setenv NODE_ENV localhost

if you want to make the variable persistent and avoid rebooting.

See:

http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-slash-etc-slash-launchd-dot-conf/

Venetis answered 26/8, 2014 at 13:39 Comment(6)
How is launchctl relevant?Pellikka
So you don't have to reboot. See: #2519792 Are you a Mac owner? It's common practiceVenetis
More references: codepulsive.blogspot.com.es/2013/11/… apple.stackexchange.com/questions/51677/…Venetis
Hmm. I took the question to be about [t]csh vs. bash (the authors of the other answers made the same assumption), but apparently it also has something to do with node.js, which I'm not familiar with. Still, I think the setenv command the OP was asking about is the builtin command in [t]csh. export NODE_ENV=localhost in bash, is exactly equivalent to setenv NODE_ENV localhost in [t]csh. The OP doesn't appear to have been asking how to make the setting persistent; that would be a separate question. Is there some obvious connection between node.js and launchctl?Pellikka
Ok fair enough, but since the author does not mention shell differences I did not realize that. No, there's no connection whatsoever between node.js and launchctlVenetis
@KeithThompson - I am not sure why you keep pushing this question of relevancy and about the relationship to node. I suspect you know there is no obvious connection between node.js and launchctl. Node js happened to be the example only. The variable could have been called NOT_NODE; it's just a name.Uranyl
A
0

Are you a Cshell person?

The earlier versions of OS X came with tcsh as the default shell since OS X is based upon BSD. However, Mac OS X comes with BASH as the user's default shell.

Macs still come with Turbo Csh too and you can make this your default shell if that is your desire. In the terminal, type:

$ chsh -s /bin/tcsh

If you decide you want switch back to BASH:

$ chsh -s /bin/bash

You can see a list of all possible shells in the /etc/shell file.

Askins answered 24/9, 2013 at 20:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.