Environment variable in GNOME, Scientific Linux 6.1 - bash

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.

Related

$PATH in VSCODE terminal through WSL2 not set correctly

I'm running Ubuntu-20.04 through WSL2 on my Windows 10 laptop. I've started having an issue in VSCode where the integrated terminal isn't getting its $PATH initialized correctly.
If I open an Ubuntu shell through Windows Terminal and run echo $PATH I get the following output:
/home/<user>/bin:/home/<user>/.nvm/versions/node/v15.1.0/bin:/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin:/opt/devkitpro/tools/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files (x86)/ATI Technologies/ATI.ACE/Core-Static:/mnt/c/Program Files (x86)/AMD/ATI.ACE/Core-Static:/mnt/c/Program Files (x86)/Calibre2/:/mnt/c/Program Files/Calibre2/:/mnt/c/Program Files/PuTTY/:/mnt/c/Program Files/FileBot/:/mnt/c/Users/<User>/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/<User>/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin
However once connected to WSL through VSCode if I run the same command in the integrated terminal I get:
/home/<user>/.local/bin
This means I can't even run the most basic commands like ls.
I can't understand why this is happening? Is there some setting in VSCode that would be interfering with my shell initialization, preventing $PATH from getting set correctly? I can't even run env to see what other environmental variables are doing.
The default shell in VSCode is set to bash.
It is my understanding that bash reads instructions from /etc/profile which sets shell variables. Could there be any reason these instruction are not being read?
Ok so I figured out what was causing the issue.
In my .bashrc, I had added the line:
export `PATH="/home/<user>/.local/bin"`
presumably to be able to access programs located there from any directory. For whatever reason this wasn't causing an issue when a shell was launched from Windows Terminal, but VS Code did not like it! Simply removing the aforementioned line from .bashrc solved the problem.
Guess I've got a lot to learn about .bashrc, .bash_profile, etc., and how these are accessed when starting up a bash shell. If anyone wants to shed light on this, feel free to comment below.

Setting environment variables in Yosemite

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.

OSX 10.9 Mavericks environment variables: how to set environment variables

How I can EXPORT environment variable not just for one tab but for all system?
If i will use export JAVA_HOME=/Library/Java/Home it will set JAVA_HOME only for current terminal tab and after system restart I will need do it one more time.
How I can set environment variable globally to make by default?
How I can edit variables in $ env list?
Add an entry to ~/.bash_profile:
export JAVA_HOME=/Library/Java/Home
save it, (or create it if it doesn't exist)
quit Terminal.app
re-launch and you're in business.
This is the best place to add the entry in my opinion, although for the distinct differences on OS X of where to add environment variables specifically for one reason or another see:
https://apple.stackexchange.com/a/13019
And for a more generalized UNIX overview:
What's the difference between .bashrc, .bash_profile, and .environment?
You can set environment variables by adding the export commands to various configuration files. E.g. ~/.profile
You can find out more about what files can be used to modify your bash environment by reading the bash manual (man bash). If you're using a different shell then it's probably similar and its man page should contain the same info. You can also read this answer on unix.stackexchange.com, which has some of these details.
If you want to set environment variables for your entire user environment, including GUI applications, I believe you can do that using ~/.MacOSX/environment.plist.

how to make emacs recognize bash environment variables, including self-defined ones

I have this need to let Emacs recognize all the shell environment variables.
The current setup:
I use VirtualBox and launch Emacs there to remotely access server files via the Tramp mode. When i do c-x c-f, and type
$RESOURCE_HOME/foo.bar
Emacs can't recognize this path, even if this is a valid path on the server -- $RESOURCE_HOME is a self-defined var.
I know this question's been answered there: How do I make Emacs recognize bash environment variables for compilation?
But there are so many self-defined variables that I don't want to write them manually.
I wonder if it's possible to solve it in a better way.
NOTE: i'm using Tramp mode, so please clarify your ideas saying vbox machine vs. server machine. Thanks!
Emacs already lets you use envvars like you suggest above. So your problem is that those vars aren't defined in Emacs's environment. Most likely it's because you define those vars in your shell's init file but that you start Emacs from a context where the shell hasn't been involved so those init files haven't been started yet.
If so, a simple fix is to start Emacs from a shell.

Setting an environment variable in Cygwin

I have been trying to setup a environment variable in Cygwin using the command export PRIMOSBASE=/directory/for/primosfiles.
And when i check the variable using the command echo $PRIMOSBASE it shows the /directory/for/primosfiles. hopeful this means the environment variable is set.
But when i try to run a shell script(primos) for the /directory/for/primosfiles, it shows
./primos: line 8: /prilaunch.pl: No such file or directory
chmod: failed to get attributes of `step1.sh': No such file or directory
which means i have not set the PRIMOSBASE environment. could anyone please tell me where i am going wrong...
Thanks ...
Run
echo "export PRIMOSBASE=/directory/for/primosfiles" >> ~/.bashrc
to append the command to the end of your .bashrc file, so that the variable is set each time you use Cygwin. Then run
source ~/.bashrc
to make it take effect immediately.
NOTE: Make sure you use double brackets (>>) to append. It might be a good idea to make a backup of .bashrc just in case. If you're not comfortable with I/O redirection, an alternative is to edit .bashrc with an editor. I think vim is among the default tools in Cygwin.
I had a similar issue trying to get ANDROID_HOME to work in a Cygwin window. When I used the linux path separators, as follows
ANDROID_HOME=/cygdrive/c/Users/User/AppData/Local/Android/sdk my gradlew build script complained it couldn't find the sdk in ANDROID_HOME.
I eventually discovered that I had to set my environment variable in the Windows format, including Windows path separators '\', as follows
ANDROID_HOME=C:\Users\User\AppData\Local\Android\sdk
Note: the PATH and several other environment variables set in Windows are converted into Linux format. I hope this helps others who want/need to use Cygwin + Windows + essentially Windows programs that need environment variables.

Resources