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.

Filter by
Sorted by
Tagged with
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?
Amit Yadav's user avatar
  • 33.6k
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 ...
A. K.'s user avatar
  • 36.2k
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'].
Jayesh's user avatar
  • 52.7k
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.
Anup Prakash's user avatar
  • 14.6k
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
AJcodez's user avatar
  • 33k
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"...
prahallada's user avatar
  • 12.4k
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:).
Nicola Cossu's user avatar
  • 55.5k
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 ...
hugo19941994's user avatar
  • 11.6k
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....
Z Douglas's user avatar
  • 9,601
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 ...
Paul Wicks's user avatar
  • 64.3k
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 ...
ILikeTacos's user avatar
  • 18.1k
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 ...
Netorica's user avatar
  • 19k
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?
Eric Schoonover's user avatar
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 ...
Jason Kim's user avatar
  • 18.6k
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 ...
Jamie Dixon's user avatar
  • 53.7k
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 ...
Ahmed Aswani's user avatar
  • 8,399
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 ...
MartyMacGyver's user avatar
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 ...
user1107173's user avatar
  • 10.5k
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 ...
Anders's user avatar
  • 12.7k
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 ...
darren's user avatar
  • 19.1k
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 ...
Salah Eddine Taouririt's user avatar
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.
Hank Gay's user avatar
  • 71.2k
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?
Mark Nguyen's user avatar
  • 7,348
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 ...
skiphoppy's user avatar
  • 100k
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"...
André Staltz's user avatar
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 ...
James's user avatar
  • 15.3k
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()
Mahendra's user avatar
  • 3,717
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 ...
Jesse Beder's user avatar
  • 33.6k
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 ...
singha's user avatar
  • 3,411
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 ...
Tomasz Mularczyk's user avatar
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 ...
Biii's user avatar
  • 3,181
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 ...
Richard Stelling's user avatar
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 ...
user987137's user avatar
  • 2,977
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:...
Michiel de Mare's user avatar
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 ...
Tom Feiner's user avatar
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)'. ...
Noel Yap's user avatar
  • 19.3k
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 ...
Kshitij Saraogi's user avatar
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?
Mister Dev's user avatar
  • 10.2k
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 ...
asidd's user avatar
  • 3,181
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 ...
Akshay Khale's user avatar
  • 8,293
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 ...
patti_jane's user avatar
  • 3,593
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 ...
user avatar
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 ...
Michał Pietraszko's user avatar
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. ...
olasammy's user avatar
  • 7,046
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: ...
Damon Yuan's user avatar
  • 3,723
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 ...
Dario's user avatar
  • 3,281
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 ...
Citronen's user avatar
  • 4,210
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() ...
raja's user avatar
  • 4,093
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 ...
Santhosh's user avatar
  • 6,637
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 ...
user1340582's user avatar
  • 19.4k

1
2 3 4 5
286