bash_profile not working as it should - linux

Hi Im running linux angstrom distribution on a remote device, I added .bash_profile and .bashrc to /home/root since they didn't exist and I wrote this in them
PATH=/opt/qt-arm/lib:$PATH
export PATH
But now when I login to this device and type $PATH I don't see the newly added path...Any Ideas??

I added .bash_profile and .bashrc to /home/root since ...
Look in /etc/passwd to check whether /home/root is actully root's home directory. On most linux distributions, it is just /root, not /home/root.
Update in response to comments:
.bash_profile and .bashrc are only inspected if the user's shell is bash. You can see what root's shell is in /etc/passwd.

Usually the home directory of the root account is /root (not in /home/root/).

Related

CentOS 6.7 Root user home deleted?

Some how I managed to delete the /root directory, so I went and recreated and set the proper permissions to the file directory. However, my command line is different and instead of showing root#my-machine# I get -bash-4.1#.
How can I fix this?
Thanks
So you deleted /root and now you have -bash-4.1# in your command line huh?
Well this is caused of a missing / corrupt .bashrc (in your case missing) file in /root (.bashrc sources /etc/bashrc which is what sets the prompt). To fix it, you will run the following command which runs when an account is created. Run as the root user (since it is the user having the problem) or you can define the destination path.
command: (make sure you are in /root)
cp -v /etc/skel/.bash* ~/
Exit terminal and log back in.
I was able to fix the error by creating a new .bashrc
Because the /root directory was removed the default .bashrc was deleted.
I fixed it by running
/bin/cp /etc/skel/.bashrc ~/
and then sourcing the new .bashrc file with source ~/.bashrc

Virtualenv: workon command not found

I have installed virtualenv and the virtualwrapper via apt-get, I got to a point where I created a virtual enviroment but however later on during that same day when I used the workon command it was not found. I further on went and inspected my home directory and .virtualenvs dir and the virtualenv I created earlier were still there.
Solving this problem took two steps:
Add this to your .bashrc / .bash_profile / .zshrc:
# load virtualenvwrapper for python (after custom PATHs)
venvwrap="virtualenvwrapper.sh"
/usr/bin/which -s $venvwrap
if [ $? -eq 0 ]; then
venvwrap=`/usr/bin/which $venvwrap`
source $venvwrap
fi
Then use:
source .bash_profile
# or .bashrc / .zshrc
to reflect the changes.
Additionally, if the terminal still sometimes cant find workon, use source .bash_profile to reset and find it again.
type source .profile in home directory from terminal.
Read the readme in the top of which virtualenvwrapper.sh
You need to source it inside bashrc
open ~/.profile
cd ~
nano .profile
add at the end
#virtualenvwrapper setup
export WORKON_HOME=$HOME/envs
export PROJECT_HOME=$HOME/dev
source /usr/local/bin/virtualenvwrapper.sh
to load your .profile file you just edited:
$ . .profile
I ran in to this problem too and I simply needed to logout and log back in.
This read in the changes which the debian package manager made to my system at /etc/bash_completion.d/virtualenvwrapper

Linux Bashrc auto-tabbing not working as subuser

I'm stuck with .bashrc at the moment. I have ~/.bashrc for root which works wonderfully. It highlights my ls and auto-completes directories with tab.
I made a new user named jesse and his home directory is under home/jesse. When I created him I did not do the "auto create directory", rather I did it manually after creating the user.
With or without a bashrc file there is no effect with colors/tabs in the user jesse. I am only guessing it had to do with the user creation not auto-creating the home directory for him. I don't understand why my tabs would be broken.
Does anyone know what I've done wrong? Should I adjust the global bash file? If so, what would cause this tab problem?
~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
export LS_OPTIONS='--color=auto'
alias ls='ls $LS_OPTIONS'
A few things could be causing this. Check to see that the jesse account is in fact using bash as the log-in shell, and not sh. Check that .bashrc is correctly named and has the right file permissions and ownership. Check that jesse's home directory has the right file permissions. Also have a look in the root user's home directory for any other bash configuration files that could affect bash completion.

How to set the environmental 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 LD_LIBRARY_PATH
Then if the terminal is closed and restarted, typing echo $LD_LIBRARY_PATH displays no result.
How to set the path permanently?
You should add more details about your distribution, for example under Ubuntu the right way to do this is to add a custom .conf file to /etc/ld.so.conf.d, for example
sudo gedit /etc/ld.so.conf.d/randomLibs.conf
inside the file you are supposed to write the complete path to the directory that contains all the libraries that you wish to add to the system, for example
/home/linux/myLocalLibs
remember to add only the path to the dir, not the full path for the file, all the libs inside that path will be automatically indexed.
Save and run sudo ldconfig to update the system with this libs.
Keep the previous path, don't overwrite it:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/
You can add it to your ~/.bashrc:
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/' >> ~/.bashrc
Add
LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"
to /etc/environment
See the Ubuntu Documentation.
CORRECTION: I should take my own advice and actually read the documentation. It says that this does not apply to LD_LIBRARY_PATH: Since Ubuntu 9.04 Jaunty Jackalope, LD_LIBRARY_PATH cannot be set in $HOME/.profile, /etc/profile, nor /etc/environment files. You must use /etc/ld.so.conf.d/.conf configuration files.* So user1824407's answer is spot on.
Alternatively you can execute program with specified library dir:
/lib/ld-linux.so.2 --library-path PATH EXECUTABLE
Read more here.
The file .bash_profile is only executed by login shells. You may need to put it in ~/.bashrc, or simply logout and login again.
For some reason no one has mentioned the fact that the bashrc needs to be re-sourced after editing. You can either log out and log back in (like mentioned above) but you can also use the commands: source ~/.bashrc or . ~/.bashrc.
Put export LD_LIBRARY_PATH=/usr/local/lib in ~/.bashrc [preferably towards end of script to avoid any overrides in between, Default ~/.bashrc comes with many if-else statements]
Post that whenever you open a new terminal/konsole, LD_LIBRARY_PATH will be reflected
Go to the home folder and edit .profile
Place the following line at the end
export LD_LIBRARY_PATH=<your path>
Save and Exit.
Execute this command
sudo ldconfig
You could try adding a custom script, say myenv_vars.sh in /etc/profile.d.
cd /etc/profile.d
sudo touch myenv_vars.sh
sudo gedit myenv_vars.sh
Add this to the empty file, and save it.
export LD_LIBRARY_PATH=/usr/local/lib
Logout and login, LD_LIBRARY_PATH will have been set permanently.
I do the following in Mint 15 through 17, also works on ubuntu server 12.04 and above:
sudo vi /etc/bash.bashrc
scroll to the bottom, and add:
export LD_LIBRARY_PATH=.
All users have the environment variable added.
In Ubuntu 20.04 Linux this is just not obvious and straight forward as it should be.
I will attempt to make it simple for anyone who is pulling out their hair just like I was with my Ubuntu 20.04.3 Linux.
Start by identifying the path where your library files' folder is located. In my case, the *.so files that I was working with were located in a folder called libs and this folder's path in my Ubuntu box is /usr/lib
So now I want to add the path /usr/lib to LD_LIBRARY_PATH such that when I run echo $LD_LIBRARY_PATH in my Ubuntu terminal I will be able to see the path /usr/lib echoed as shown below;
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
Here are the steps I used
Open terminal in Ubuntu 20.04 Linux box
Change path to /etc/ld.so.conf.d/ by running cd /etc/ld.so.conf.d/
Create a file with a *.conf extension at the end with a text editor
like e.g. vim or gedit in my case I created it as follows sudo gedit my_project_libs.conf
Inside the .conf file that I created named my_project_libs.conf
I added the path to my libs by adding this line export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
Thereafter, I then run gedit ~/.bash_profile to open the
~/.bash_profile file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want
included in LD_LIBRARY_PATH
I also ran gedit ~/.bashrc to open the
~/.bashrc file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want
included in LD_LIBRARY_PATH
When you are done adding the line in step 5, save and close.
In your terminal, type the following sudo ldconfig and press
enter on your keyboard.
Close all your open terminals that you were using then open a new terminal session and run echo $LD_LIBRARY_PATH If you see the path you added is echoed back, you did it right.
In my case, this is what I see :/usr/lib when I run echo $LD_LIBRARY_PATH in my newly opened Ubuntu terminal session
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
That's how I got it to work for me in my Ubuntu 20.04.3 Linux box.
Everyone seems to be missing the forest for the trees.
The real answer is that '~/.bash_profile' is by default only sourced for LOGIN SHELLS.
The bash config file you are probably looking for if you are starting and closing terminals from your desktop GUI is '~/.bashrc', which is the file sourced by default when starting interactive, non-login shells.
https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc

Safely change home directory

I'm trying to safely update the home directory as specified in /etc/passwd,
but the standard Linux utils - usermod and vipw - for doing so aren't provided
by Cygwin.
Could anyone tell me how they changed this in Cygwin?
EDIT: For recent versions of Cygwin (1.7.34 and beyond), see this newer question.
Like sblundy's answer, you can always edit by-hand.
But if you want to do it the "official" way, use the cygwin-specific mkpasswd command. Below is a snippet from the official docs on mkpasswd :
For example, this command:
Example 3.11. Using an alternate home root
$ mkpasswd -l -p "$(cygpath -H)" > /etc/passwd
would put local users' home directories in the Windows 'Profiles' directory.
There's a bunch of other really useful commands described on the Cygwin Utilities documentation page (which includes mkpasswd). The use of cygpath in the example above is another of these cygwin-specific tools.
While you're at it, you probably also want to read the Using Cygwin Effectively with Windows documentation. There's a bunch of really good advice.
I ended up exiting all my cygwin shells and editing it by hand in a text editor. So far, so good.
Note: don't escape the spaces in the "Documents and Settings" directory. The entry will look like
user:...:/cygdrive/c/Documents and Settings/user:/bin/bash
The line is tokenized on the : character.
The simplest answer I have found is to make /home to be a soft link to your Windows Home/UserProfile directory
cd /
mv home oldhome
ln -s "$(cygpath -H)" home
I used cygpath as it will get the proper location for the HOME directory on the current version of Windows. On my box cygpath -H returns /cygdrive/c/Users
For the current user the following worked for me:
Close Cygwin.
Set the HOME Windows user environment variable.
Start Cygwin.
run "mkpasswd -c -p "$(cygpath -H)" > /etc/passwd".
Restart Cygwin.
I confirmed it worked by running ssh-keygen without any arguments. After making this change the app now defaults to saving the key to /cygdrive/c/Users/user instead of /home/user.
I don't know if setting HOME is required, but I did it anyway per instructions for setting up TortoiseGit with Cygwin using Tortoise's official documentation for unofficial Cygwin support here. Setting HOME alone though was not enough for ssh-keygen to recognize the home directory change.
Also, note that Cygwin's official documentation on this issue can be found here.
Confirmed in Windows 7 using 64-bit Cygwin v1.7.35.
I always set HOME as a user-specific environment variable in Computer Properties.
To avoid problems caused by having spaces in the path to your home directory, use the short-form of the Windows 'Profiles' directory - i.e. /cygdrive/c/DOCUME~1/user.
You can do this by typing the command:
mkpasswd -l -p "$(cygpath $(cygpath -dH))" > /etc/passwd
Original answer by Christopher from elsewhere
Cygwin 1.7.34+
For those using Cygwin 1.7.34 or higher Cygwin supports configuring how to fetch home directory, login shell, and gecos information in /etc/nsswitch.conf. This is detailed in the Cygwin User Guide section:
Cygwin user names, home dirs, login shells
If you've previously created an /etc/passwd or /etc/group file you'll want to remove those and configure Cygwin using the new Windows Security model to POSIX mappings.
[[ -f /etc/passwd ]] && mv /etc/passwd /etc/passwd.bak
[[ -f /etc/group ]] && mv /etc/group /etc/group.bak
The /etc/nsswitch.conf file's db_home: setting defines how Cygwin fetches the user's home directory. The default setting for db_home: is
db_home: /home/%U
So by default, Cygwin just sets the home dir to /home/$USERNAME. You can change that though to point at any other custom path you want. The supported wildcard characters are:
%u The Cygwin username (that's lowercase u).
%U The Windows username (that's uppercase U).
%D Windows domain in NetBIOS style.
%H Windows home directory in POSIX style. Note that, for the db_home: setting, this only makes sense right after the preceeding slash, as in db_home: /%H/cygwin
%_ Since space and TAB characters are used to separate the schemata, a space in the filename has to be given as %_ (that's an underscore).
%% A per-cent character.
In place of a path, you can specify one of four named path schemata that are predefined.
windows The user's home directory is set to the same directory which is used as Windows home directory, typically something along the lines of %USERPROFILE% or C:\Users\$USERNAME. Of course, the Windows directory is converted to POSIX-style by Cygwin.
cygwin AD only: The user's home directory is set to the POSIX path given in the cygwinHome attribute from the cygwinUser auxiliary class. See also the section called “The cygwin schema”.
unix AD only: The user's home directory is set to the POSIX path given in the unixHomeDirectory attribute from the posixAccount auxiliary class. See also the section called “The unix schema”.
desc The user's home directory is set to the POSIX path given in the home="..." XML-alike setting in the user's description attribute in SAM or AD. See the section called “The desc schema” for a detailed description.
The following will make the user's home directory in Cygwin the same as is used for the Windows home directory.
db_home: windows
Cygwin 1.7.33 or earlier
For those using Cygwin 1.7.33 or earlier, update to the latest version Cygwin and remove previously used /etc/passwd and /etc/group files, then see the steps above.
Else, follow these older steps below.
Firstly, set a Windows environment variable for HOME that points to your user profile:
Open System on the Control Panel
On the Advanced tab click Environment Variables (toward the bottom)
In the User Variables area click "New…"
For Variable name enter HOME
For Variable value enter %USERPROFILE%
Click OK in all the open dialog boxes to apply this new setting
Now we are going to update the Cygwin /etc/passwd file with the Windows %HOME% variable we just created. Shell logins and remote logins via ssh will rely on /etc/passwd to tell them the location of the user's $HOME path.
At the Cygwin bash command prompt type the following:
cp /etc/passwd /etc/passwd.bak
mkpasswd -l -p $(cygpath -H) > /etc/passwd
mkpasswd -d -p $(cygpath -H) >> /etc/passwd
The -d switch tells mkpasswd to include DOMAIN users, while -l is to only output LOCAL machine users. This is important if you're using a PC at work where the user information is obtained from a Windows Domain Controller.
Now, you can also do the same for groups, though this is not necessary unless you will be using a computer that is part of a Windows Domain. Cygwin reads group information from the Windows account databases, but you can add an /etc/group file if your machine is often disconnected from its Domain Controller.
At the Cygwin bash prompt type the following:
cp /etc/group /etc/group.bak
mkgroup -l > /etc/group
mkgroup -d >> /etc/group
Now, exit Cygwin and start it up again. You should find that your HOME path points to the same location as your Windows User Profile -- i.e. /cygdrive/c/Users/username
I like to keep my cygwin installation sync'd to a pen drive and another computer, so I hate hard-coding the home directory. I use the following cygwin.bat:
echo off
SETLOCAL
set SHELL=\\bin\\bash
set HOME=%~dp0..\..\doc\unix
bin\bash --login -i
ENDLOCAL
SETLOCAL and ENDLOCAL make sure that SHELL and HOME don't clobber existing env variables for other programs. HOME=%~dp0..\..\doc\unix sets HOME to be two directories up, in the doc/unix subdirectory. Then in ....\doc\unix.bashrc, I include PATH="/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin".
I did not use start /wait %CD%\bin\bash to start bash, because I am using Console2, so I don't need an additional cmd window.
Using Windows Environment Variable: HOME
This works for me for a permanent, non-portable, non-network solution; i.e. setting the HOME Environment variable permanently in Windows.
Note that this doesn't affect ssh or telnet sessions which always refer to /etc/passwd
ref: Setting up Cygwin- My HOME environment variable is not what I want.
CMD
For current user (needs to run once per user)::
reg add HKCU\Environment /v HOME /t REG_EXPAND_SZ /d ^%USERPROFILE^%
For new Users:
reg add HKU\.DEFAULT\Environment /v HOME /t REG_EXPAND_SZ /d ^%USERPROFILE^%
Note: Carets ^ before percent-signs %
IMPORT REG FILE
Import this reg file (current user):
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Environment]
"HOME"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,00,00
For new users:
Windows Registry Editor Version 5.00
[HKU\.DEFAULT\Environment]
"HOME"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,00,00
REGEDIT
In Regedit, under:
For current user:
HKEY_CURRENT_USER\Environment
For new Users:
HKU\.DEFAULT\Environment
Create HOME as a new Expandable String Value (*REG_EXPAND_SZ*) and put in %USERPROFILE%
cd /home
rm -rf chris
ln -s /cygdrive/z chris
I am not really sure if it is the safest solution but it is a possible solution that works for me ;)
I edited my /etc/passwd file directly (making sure nothing else would be accessing it), and changed all references to /home to be /Users (on Windows 7). I found that, in order for everything to work correctly, I had to delete any directories in the /home directory (or move them to the appropriate other location). Otherwise, cygwin would develop a split personality where, for example, 'bash -l' would start in /home/Pablo but $HOME would be /Users/Pablo and emacs would appear to do the reverse. Once I deleted /home/Pablo, everything worked fine.
I only needed to be in C:\Users\username when I start cygwin. So, I just added to .bashrc and .profile
cd ${HOMEPATH}
If you prefer to use ~/. instead of $HOMEPATH, you can also add the following:
export HOME=${HOMEPATH}
This way I don't disturb the cygwin installation.

Resources