Questions tagged [environment-variables]
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.
14,283
questions
3264
votes
17
answers
3.0m
views
How can I access environment variables in Python?
How can I get the value of an environment variable in Python?
2382
votes
7
answers
1.6m
views
How do I delete an exported environment variable?
Before installing gnuplot, I set the environment variable GNUPLOT_DRIVER_DIR = /home/gnuplot/build/src. During the installation, something went wrong.
I want to remove the GNUPLOT_DRIVER_DIR ...
1554
votes
11
answers
913k
views
Read environment variables in Node.js
Is there a way to read environment variables in Node.js code?
Like for example Python's os.environ['HOME'].
1435
votes
37
answers
2.2m
views
How to get the client IP address in PHP
How can I get the client IP address using PHP?
I want to keep record of the user who logged into my website through his/her IP address.
1399
votes
21
answers
1.9m
views
How do I pass environment variables to Docker containers?
How can one access an external database from a container? Is the best way to hard code in the connection string?
# Dockerfile
ENV DATABASE_URL amazon:rds/connection?string
1216
votes
20
answers
2.0m
views
How to set environment variables in Python?
I need to set some environment variables in the Python script and I want all the other scripts that are called from Python to see the environment variables' set.
If I do,
os.environ["DEBUSSY"...
1180
votes
8
answers
1.9m
views
List all environment variables from the command line
Is it possible to list all environment variables from a Windows' command prompt?
Something equivalent to PowerShell's gci env: (or ls env: or dir env:).
1135
votes
50
answers
1.0m
views
Set environment variables from file of key/value pairs
TL;DR: How do I export a set of key/value pairs from a text file into the shell environment?
For the record, below is the original version of the question, with examples.
I'm writing a script in bash ...
949
votes
4
answers
460k
views
What are the special dollar sign shell variables?
In Bash, there appear to be several variables which hold special, consistently-meaning values. For instance,
./myprogram &; echo $!
will return the PID of the process which backgrounded myprogram....
939
votes
33
answers
885k
views
Setting environment variables on OS X
What is the proper way to modify environment variables like PATH in OS X?
I've looked on Google a little bit and found three different files to edit:
/etc/paths
~/.profile
~/.tcshrc
I don't ...
755
votes
4
answers
522k
views
In a Dockerfile, How to update PATH environment variable?
I have a dockerfile that download and builds GTK from source, but the following line is not updating my image's environment variable:
RUN PATH="/opt/gtk/bin:$PATH"
RUN export PATH
I read that that I ...
739
votes
21
answers
2.3m
views
Adding a directory to the PATH environment variable in Windows
I am trying to add C:\xampp\php to my system PATH environment variable in Windows.
I have already added it using the Environment Variables dialog box.
But when I type into my console:
C:\>path
it ...
694
votes
30
answers
841k
views
Is there a command to refresh environment variables from the command prompt in Windows?
If I modify or add an environment variable I have to restart the command prompt. Is there a command I could execute that would do this without restarting CMD?
662
votes
27
answers
2.0m
views
Error "'git' is not recognized as an internal or external command"
I have an installation of Git for Windows, but when I try to use the git command in Command Prompt, I get the following error:
'git' is not recognized as an internal or external command,
operable ...
624
votes
4
answers
1.2m
views
Defining and using a variable in batch file
I'm trying to define and use a variable in a batch file. It looks like it should be simple:
@echo off
set location = "bob"
echo We're working with "%location%"
The output I get ...
586
votes
7
answers
474k
views
How to keep environment variables when using sudo [closed]
When I use any command with sudo the environment variables are not there. For example after setting HTTP_PROXY the command wget works fine without sudo. However if I type sudo wget it says it can't ...
574
votes
7
answers
458k
views
Setting an environment variable before a command in Bash is not working for the second command in a pipe
In a given shell, normally I'd set a variable or variables and then run a command. Recently I learned about the concept of prepending a variable definition to a command:
FOO=bar somecommand someargs
...
548
votes
20
answers
1.0m
views
Setting Environment Variables for Node to retrieve
I'm trying to follow a tutorial and it says:
There are a few ways to load credentials.
Loaded from environment variables,
Loaded from a JSON file on disk,
The keys need to be as ...
545
votes
16
answers
901k
views
Set environment variables on Mac OS X Lion
When someone says "edit your .plist file" or "your .profile" or ".bash_profile" etc, this just confuses me. I have no idea where these files are, how to create them if I have to do that, etc, and also ...
474
votes
24
answers
2.0m
views
How to add to the PYTHONPATH in Windows, so it finds my modules/packages? [duplicate]
I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my PYTHONPATH so I can call the apps directly.
I tried adding C:\My_Projects\; to my Windows ...
473
votes
13
answers
521k
views
Can I export a variable to the environment from a Bash script without sourcing it?
Suppose that I have this script:
export.bash:
#! /usr/bin/env bash
export VAR="HELLO, VARIABLE"
When I execute the script and try to access to the $VAR, I don't get any value!
echo $VAR
Is ...
465
votes
9
answers
503k
views
What is the LD_PRELOAD trick?
I came across a reference to it recently on proggit and (as of now) it is not explained.
I suspect this might be it, but I don't know for sure.
432
votes
17
answers
753k
views
How to set NODE_ENV to production/development in OS X
For use in express.js environments. Any suggestions?
412
votes
24
answers
672k
views
How do I set environment variables from Java?
How do I set environment variables from Java? I see that I can do this for subprocesses using ProcessBuilder. I have several subprocesses to start, though, so I'd rather modify the current process's ...
385
votes
5
answers
296k
views
Difference between os.getenv and os.environ.get
Is there any difference at all between both approaches?
>>> os.getenv('TERM')
'xterm'
>>> os.environ.get('TERM')
'xterm'
>>> os.getenv('FOOBAR', "not found") == "not found"...
377
votes
21
answers
436k
views
Where can I set environment variables that crontab will use?
I have a crontab running every hour. The user running it has environment variabless in the .bash_profile that work when the user runs the job from the terminal, however, obviously these don't get ...
358
votes
13
answers
456k
views
Recommended way to get hostname in Java
Which of the following is the best and most portable way to get the hostname of the current computer in Java?
Runtime.getRuntime().exec("hostname")
vs
InetAddress.getLocalHost().getHostName()
355
votes
4
answers
675k
views
How can I add a default include path for GCC in Linux?
I'd like GCC to include files from $HOME/include in addition to the usual include directories, but there doesn't seem to be an analogue to $LD_LIBRARY_PATH.
I know I can just add the include directory ...
334
votes
12
answers
1.5m
views
How to set the environment variable LD_LIBRARY_PATH in linux
I have first executed the command: export LD_LIBRARY_PATH=/usr/local/lib
Then I have opened .bash_profile file: vi ~/.bash_profile.
In this file, I put:
LD_LIBRARY_PATH=/usr/local/lib
export ...
327
votes
17
answers
401k
views
Test process.env with Jest
I have an application that depends on environmental variables like:
const APP_PORT = process.env.APP_PORT || 8080;
And I would like to test that for example:
APP_PORT can be set by a Node.js ...
313
votes
12
answers
726k
views
Adding an .env file to a React project [duplicate]
I'm trying to hide my API Key for when I commit to GitHub, and I've looked through the forum for guidance, especially the following post:
How do I hide an API key in Create React App?
I made the ...
303
votes
7
answers
125k
views
How do I print a list of "Build Settings" in Xcode project?
Alternate Titles
List of Xcode build variables
Print a list of Xcode Build Settings
Clang Environment Variables
Canonical list of Xcode Environment Variables
Is there a Canonical list of Xcode ...
296
votes
6
answers
1.4m
views
javac is not recognized as an internal or external command, operable program or batch file [closed]
I am experiencing an error while trying to compile Java programs.
I am on Windows (this is a Windows-specific problem) and I have the latest JDK installed.
I have attempted a solution involving the ...
295
votes
18
answers
153k
views
Why does sudo change the PATH? [closed]
This is the PATH variable without sudo:
$ echo 'echo $PATH' | sh
/opt/local/ruby/bin:/usr/bin:/bin
This is the PATH variable with sudo:
$ echo 'echo $PATH' | sudo sh
/usr/local/sbin:/usr/local/bin:...
283
votes
6
answers
237k
views
Why does an SSH remote command get fewer environment variables then when run manually? [closed]
I have a command that runs fine if I ssh to a machine and run it, but fails when I try to run it using a remote ssh command like :
ssh user@IP <command>
Comparing the output of "env" using ...
281
votes
16
answers
758k
views
How to set environment variables in Jenkins?
I would like to be able to do something like:
AOEU=$(echo aoeu)
and have Jenkins set AOEU=aoeu.
The Environment Variables section in Jenkins doesn't do that. Instead, it sets AOEU='$(echo aoeu)'.
...
277
votes
6
answers
293k
views
What is a good practice to check if an environment variable exists or not?
I want to check my environment for the existence of a variable, say "FOO", in Python. For this purpose, I am using the os standard library. After reading the library's documentation, I have figured ...
263
votes
9
answers
338k
views
How do I get and set Environment variables in C#?
How can I get Environnment variables and if something is missing, set the value?
261
votes
11
answers
272k
views
Passing bash variable to jq
I have written a script to retrieve certain value from file.json. It works if I provide the value to jq select, but the variable doesn't seem to work (or I don't know how to use it).
#!/bin/sh
#this ...
257
votes
3
answers
165k
views
How to comment in laravel .env file?
I am working on a project in Laravel where I am storing some settings in .env file setting like few parameters for testing purpose and few parameters are for live working so I was just checking that ...
256
votes
15
answers
508k
views
Setting PATH environment variable in OSX permanently
I have read several answers on how to set environment variables on OSX permanently.
First, I tried this, How to permanently set $PATH on Linux/Unix but I had an error message saying no such file and ...
254
votes
11
answers
467k
views
Command line to remove an environment variable from the OS level configuration
Windows has the setx command:
Description:
Creates or modifies environment variables in the user or system
environment.
So you can set a variable like this:
setx FOOBAR 1
And you can clear ...
250
votes
2
answers
348k
views
How do I set environment variables during the "docker build" process?
I'm trying to set environment variables in docker container during the build but without success. Setting them when using run command works but I need to set them during the build.
Dockerfile
FROM ...
244
votes
16
answers
148k
views
Environment variable is too large on Windows 10
I have recently upgraded to Windows 10 from Windows 8.1.
Now I wanted to set an environment variable for my new installation of Apache Maven.
Each time I created the user variable, things were fine. ...
243
votes
24
answers
280k
views
Setting environment variable in react-native?
I am using react-native to build a cross-platform app, but I do not know how to set the environment variable so that I can have different constants for different environments.
Example:
development:
...
236
votes
21
answers
343k
views
How to set ASPNETCORE_ENVIRONMENT to be considered for publishing an ASP.NET Core application
When I publish my ASP.NET Core web application to my local file system, it always takes the production-config and the ASPNETCORE_ENVIRONMENT variable with the value = "Production".
How and ...
234
votes
12
answers
358k
views
Get Environment Variable from Docker Container
What's the simplest way to get an environment variable from a docker container that has not been declared in the Dockerfile?
For instance, an environment variable that has been set through some ...
228
votes
9
answers
331k
views
How can I get System variable value in Java?
How can I get the System Variable value which is present in
MyComputer -> Properties -> Advanced -> Environment Variables -> System Variables
in Java?
Edit
I have used System.getenv() ...
228
votes
7
answers
402k
views
Setting a system environment variable from a Windows batch file?
Is it possible to set a environment variable at the system level from a command prompt in Windows 7 (or even XP for that matter). I am running from an elevated command prompt.
When I use the set ...
226
votes
6
answers
386k
views
How can I permanently export a variable in Linux?
I am running RHEL 6, and I have exported an environment variable like this:
export DISPLAY=:0
That variable is lost when the terminal is closed. How do I permanently add this so that this variable ...