I have my bashrc file in /opt/distra/bashrc and trying to add a path in LD_LIBRARY_PATH variable but the changes are not reflecting after closing the terminal and re-starting and re starting the Linux Machine.
OS : Oracle Linux 7.7
My bashrc looks like this
# User specific environment variables
export DISTRA_USER=$USER
export M2_HOME=/opt/maven/apache-maven-3.0.5
export JAVA_HOME=/usr/java/default
export BT3_HOME=/opt/distra/bt3
export LD_LIBRARY_PATH=/opt/oracle/product/18c/dbhomeXE/lib:/opt/distra/executive/current/lib:/opt/mqm/java/lib64
I am trying to add :/opt/mqm/java/lib64 to the LD_LIBRARY_PATH variable
I have to do . /opt/distra/bashrc everytime i start my machine. There must be some way that i am not aware of to make the change permanently.
What shall i do to make the changes permanent ?
Edit :
My .bashrc in home directory has the following lines:
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Source distra definitions
if [ -f /opt/distra/bashrc ]; then
. /opt/distra/bashrc
fi
My .bash_profile in home directory has the following lines:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:$HOME/scripts
export PATH
The line "export LD_LIBRARY_PATH=/opt/oracle/product/18c/dbhomeXE/lib:/opt/distra/executive/current/lib**:/opt/mqm/java/lib64**"
looks bogus because: 1) LD_LIBRARY_PATH should contain only directory paths, not individual library archive paths; and 2) since this entry is unquoted, the shell wildcards "**" will be expanded; I don't think this is what you really want. Try:
export LD_LIBRARY_PATH='/opt/oracle/product/18c/dbhomeXE/lib:/opt/distra/executive/current/lib:/opt/mqm/java/lib64'
i.e., enclose the value in single quotes. This really isn't necessary here but the single quotes will keep you safe from directories with embedded whitespace, not that you should actually use those on a Linux box.
Related
When starting a new shell, the PATH environment variable is not configured
properly. The directories anaconda3/bin or miniconda3/bin are at second
position only, not at first position in the PATH variable. This can be
resolved by conda deactivate and activating it again.
This question was asked several times already (e.g. here and here)
but the existing questions are either very old or concentrate on the use of
source activate env-name. All in all, I found no answer that resolves my
problem.
When I start a new shell, the base environment is activated. The relevant
snippet from my .bashrc reads like this:
condaexe="/home/$USER/.miniconda3/bin/conda"
condash="/home/$USER/.miniconda3/etc/profile.d/conda.sh"
__conda_setup="$($condaexe 'shell.bash' 'hook' 2> /dev/null)"
# shellcheck disable=SC2181
if [[ $? -eq 0 ]]
then
eval "$__conda_setup"
elif [[ -f "$condash" ]]
then
source "$condash"
fi
unset __conda_setup condaexe condash
Then, the PATH variables are defined as follows:
(base)$ echo $PATH
/home/user/.local/bin:/home/user/.miniconda3/bin:/home/user/.miniconda3/condabin:/home/user/workspace/my-project/:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base)$ conda deactivate && echo $PATH
/home/user/.local/bin:/home/user/.miniconda3/condabin:/home/user/workspace/my-project/:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ conda activate base && echo $PATH
/home/user/.miniconda3/bin:/home/user/.local/bin:/home/user/.miniconda3/condabin:/home/user/workspace/my-project/:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
(base)$
Note that /home/user/.local/bin is contained twice; once before and once
after the Miniconda3 directories.
I tried to debug the problem by appending the following snippet to .bashrc:
echo $CONDA_PROMPT_MODIFIER
echo $PATH
This yields
(base)
/home/user/.miniconda3/bin:/home/user/.miniconda3/condabin:/home/user/workspace/my-project:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
which would be perfectly fine but, somehow, is modified after .bashrc.
Note that here /home/user/.local/bin is contained only once.
What goes on here? How can I setup Bash/Conda to get a properly defined PATH
environment variable?
There are three components I missed in the original question which are key to the solution.
First, I run all my shells inside TMux. Second, TMux sources the .profile. Third, in .profile some local directories like the aformentioned ~/.local/bin are blindly prepended to the PATH.
Taken this altogether all the weird behaviour above makes sense. Especially that PATH is correct at the end of ~/.bashrc but not in the shell is obvious now; it got modified in between by ~/.profile.
There are three solutions for this:
deactivating and activating conda manually (temporary workaround)
being more picky about which shells are started inside TMux (very unhandy)
commenting out the manipulations of PATH in ~/.profile
It seems as if one cannot configure TMux to source only ~/.bashrc (reference 1, reference 2), albeit some workarounds exist here too.
This is related to the Bash init files. By default, ~/.bashrc is used in an interactive, non-login shell. It won't be sourced in a login shell. Tmux uses a login shell by default. Hence, shells started by tmux skip ~/.bashrc.
default-command shell-command
The default is an empty string, which instructs tmux to create a login shell using the value of the default-shell option.
Init files for Bash,
login mode:
/etc/profile
~/.bash_profile, ~/.bash_login, ~/.profile (only first one that exists)
interactive non-login:
/etc/bash.bashrc (some Linux; not on Mac OS X)
~/.bashrc
non-interactive:
source file in $BASH_ENV
The weird interactive, non-login loading requirement confuses people in other situations as well. The best solution is to change the loading requirement of ~/.bashrc as interactive only, which is exactly what some distros, like Ubuntu, are doing.
# write content below into ~/.profile, or ~/.bash_profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
This should be the solution you desire. And I recommend every Bash user setup this in the profile.
References
Unix Shell Initialization
man tmux
Thanks for this post! That give me hint to debug same issue. I think everyone is different situdation but the idea is same: there is a command like export $PATH change the path in your zshrc or .bashrc which will affect the computer to find the path you want.
I would like to add a PYTHONPATH to my .bash_profile but would like to check I'm doing this the correct way. My .bash_profile (without a PYTHONPATH) looks like:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/user/condor/bin:/home/user/merlin/bin
export PATH
The path I would like to add to my PYTHONPATH is:
/home/user/merlin/bin/strats/
Therefore would my updated .bash_profile (with PYTHONPATH) looks like:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/user/condor/bin:/home/user/merlin/bin
export PATH
export PYTHONPATH=/home/user/merlin/bin/strats/
How can I correctly format this?
If it's your wish to be the sole owner and decision maker regarding PYTHONPTAH environment variable content on your interactive login shells, you're doing it right:
~/.bash_profile or ~/.profile
export PYTHONPATH=/home/user/merlin/bin/strats/
If you'd like to inherit any system-wide setting for PYTHONPATH environment variable, then you should:
~/.bash_profile or ~/.profile
export PYTHONPATH=$PYTHONPATH:/home/user/merlin/bin/strats/
Be aware that if you're working in a system where you can launch new terminals without logging in (i.e: launching a new xterm on your linux desktop), or in case you need that specific environment variable to run a script via cron, .bash_profile won't be executed and therefore the environment variable won't be available to that script.
As discussed in this answer comments, you can choose to use the ./~profile file instead of ~/.bash_profile to have additional compatibility with other shells.
Some folks simply add all environment configuration in ~/.bashrc. Since your .bash_profile template call ~/.bashrc, you'd end up having those environment variables available in interactive login and non-login shells.
For scripts that run via cron, you should directly source the file where you have your environment configuration on the script itself or on the cron line because that won't be done automatically for you (crontab launches non-interactive shells to run the scripts and these are not affected by ~/.bashrc, ~/.bash_profile or ~/.profile).
My .bash_profile looks like:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/home/user/condor/bin:/home/user/merlin/bin
export PATH
I just added :/home/user/merlin/bin to my PATH
However when I echo $PATH I see the following:
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/user/scoleman/bin:/home/scoleman/bin:/home/user/.local/bin:/home/user/bin:/home/user/condor/bin:/home/user/scoleman/bin:/home/scoleman/bin
I don't see the new path that I added (:/home/user/merlin/bin) and is also different to what is in my .bash_profile
Ultimatly I'm trying to add the following new project path:
:/home/user/merlin/bin/strats/
But I'm now unsure as to where I should be adding the new path or if I should be doing something after I've added the new path to my .bash_profile?
Why does the .bash_profile script have a different set of paths compared to echo $PATH?
Bash will source automatic profiles such as .bashrc. --rcfile option can be used to override the automatic script. But I need to source additional personalized file (that's the automatic script plus another file) when launching the bash shell without touching ANY files in $HOME or /etc directory since $HOME directory belongs to application run user. The personalized file must not be located in $HOME directory.
Is this possible?
I tried:
/bin/bash <<EOF
. /a-directory-outside-of-home/vanilla
EOF
but it returned to the current shell.
Okay, so you want to run the user's normal .bashrc, followed by your own script, and you want to trigger this behavior in the way that bash is called, correct?
The call:
/bin/bash --rcfile myscript
First line of myscript:
source $HOME/.bashrc
bash --rcfile <(cat rcfile1; cat rcfile2)
works just fine and requires no modifications anywhere.
Add your stuff as *.sh files in /etc/profile.d -- read /etc/profile and
http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files
I wouldn't modify the .bashrc file. Instead, I would modify the .bash_profile
file which is located at $HOME.
It is the place from where .bashrc is included.
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/bashrc
fi
A good option for you is to add a .personalized_settings file and include it
just below the above lines like this.
# Adding personalized settings
if [ -f ~/.personalized_settings ]; then
. ~/personalized_settings
fi
This requires that .personalized_settings file is located at $HOME.
I have tested the above in Fedora12.
Edit :
You might need to look for .profile instead of .bash_profile in Ubuntu (and hopefully other Debian based systems). (courtesy #Benjamin W.)
This (link)[https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files] will give you more information on it.
What if you mess around with any of the profile files?
You have a back-up copy of all these files in /etc/skel which you could
use to restore.
I just started to learning C Language.
My system is OS X 10.10 and MacVim 7.4.383 compiled by myself because I need it support python3.
But I find if a just double cilck the MacVim.app and :open ~/Desktop/something.c, it will tell me that something.c is a new file. But I did have a file called something.c on my Desktop, and I search the reason of situation, it seem to there is something about environment variable, so I follow the guide to add this code to file:///etc/launchd.conf
setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
and restart my computer, it didn't change anything
and my /etc/bashrc is
System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
return
fi
PS1='\d \A \u # \H \w #\#: \$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi
# ===== ===== ===== =====
# Custom Setting
export CLICOLOR=1
export LSCOLORS=gxfxaxdxcxegedabagacad
export HISTSIZE=250
# Setting PATH for KDE
export KDEDIRS=$KDEDIRS:$HOME/Library/Preferences/KDE:/usr/local/kde4
export PATH=/usr/local/kde4/bin:$PATH
export DYLD_LIBRARY_PATH=/usr/local/kde4/lib:$DYLD_LIBRARY_PATH
launchctl setenv DYLD_LIBRARY_PATH /usr/local/kde4/lib:$DYLD_LIBRARY_PATH
export XDG_DATA_HOME=$HOME/Library/Preferences/KDE/share
export XDG_DATA_DIRS=/usr/local/kde4/share:/usr/local/share:/usr/share
# Setting PATH for MySQL
export PATH=$PATH:/usr/local/mysql/bin/
# Setting PATH for Node.js and NPM
export PATH=$PATH:/usr/local/bin/node
export PATH=$PATH:/usr/local/bin/npm
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
And if I used absolute path like this
:open /Users/XXX/Desktop/something.c
it will print an error
E479:Not match
E32:No file name
So, what can I do to make the MacVim work like just under linux, thank you.
:open is not used for opening a file. You need to use :edit or :e command for that.
You can just use:
:e /Users/XXX/Desktop/something.c
Also $PATH doesn't have any impact on :e command.
As per vim help:
1: Simulated command simulated-command
This command is in Vi, but Vim only simulates it:
*:o* *:op* *:open* :[range]o[pen] Works like |:visual|: end Ex mode.
{Vi: start editing in open mode}
:[range]o[pen] /pattern/ As above, additionally move the cursor to the
column where "pattern" matches in the cursor
line.
Vim does not support open mode, since it's not really useful. For
those situations where ":open" would start open mode Vim will leave Ex
mode, which allows executing the same commands, but updates the whole
screen instead of only one line.