I'm working on a bash script that appends to /etc/profile
but instead of appending, I accidentally wrote over it, losing all of its content. How can I restore the file? I did search here but being new to Ubuntu, I don't know if the posted /etc/profile
content I see in other questions is the default content.
I have been playing around with the ~/.profile
file trying to add something permanently to my $PATH
variable and it seems i have done some damage.
I can't log into ubuntu now. When I enter my password the screen goes black for 1 second and then it goes back to the login screen. If I press Ctrl+Alt+F3 I can log in with the command line. My question is how can I edit ~/.profile
from the command line so I can log in again ?
I'm trying to integrate RVM with gnome-terminal.
Per default, gnome-terminal does not start bash as a login shell. I enabled run command as a login shell
as suggested in this answer about the same topic setting up RVM, but when I do this the .bashrc
file is not read.
For example, I create an environment variable in .bashrc
and then when I start a new gnome-terminal I cannot read it. I need to run explicitly source .bashrc
to read the file.
Is this the expected behavior?
Problem
I have an Ubuntu 11.04 Virtual Machine and I wanted to set up my Java development environment. I did as follows
sudo apt-get install openjdk-6-jdk
Added the following entries to ~/.bash_profile
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk export PATH=$PATH:$JAVA_HOME/bin
Save the changes and exit
Open up a terminal again and typed the following
echo $JAVA_HOME (blank) echo $PATH (displayed, but not the JAVA_HOME value)
Nothing happened, like if the export of JAVA_HOME and it's addition to the PATH were never done.
Solution
I had to go to ~/.bashrc and add the following entry towards the end of file
#Source bash_profile to set JAVA_HOME and add it to the PATH because for some reason is not being picked up
. ~/.bash_profile
Questions
- Why did I have to do that? I thought bash_profile, bash_login or profile in absence of those two get executed first before bashrc.
- Was in this case my terminal a non-login shell?
- If so, why when doing su after the terminal and putting the password it did not execute profile where I had also set the exports mentioned above?
I use GNOME and it first executes commands from /etc/profile
and then from ~/.profile
. This I have found by putting statements like echo 'something' > test
in all files that i could think of like .bashrc, .bash_profile, .profile, /etc/profile and others.
What I am curious about is to know if there is any standard file that all Desktop Managers are required to execute commands from? is there any agreement between Desktop Mangers in this regard or do they use which ever file they want.