PDA

View Full Version : Messed up /etc/enviroment



calvar
23rd November 2017, 05:14 PM
Hi!

I was installing java 8 and I wrote

export JAVA_HOME=/opt/jdk1.8.0_151
export JRE_HOME=/opt/jdk1.8.0_151/jre
export PATH=$PATH:/opt/jdk1.8.0_151/bin:/opt/jdk1.8.0_151/jre/bin

onto /etc/environment

Now most commands do not work, including sudo and the text editors to try to change back environment.
How can I revert the /etc/environment to its default value?

Thank you for your help

HaydnH
23rd November 2017, 05:20 PM
Just checked my /etc/enviroment and it's an empty file, so this would work:


echo "" > /etc/environment

HaydnH
23rd November 2017, 05:25 PM
For future situations where the file isn't blank, you can find which package the file belongs to with dnf, move the file out the way and the reinstall it:



# dnf provides /etc/environment
<Output listing setup-... as the package>
# mv /etc/environment /etc/environment.bak
# dnf reinstall setup

calvar
23rd November 2017, 05:28 PM
Thanks HaydnH,

echo is indeed still functional, the problem is that su and sudo are not, so I cannot get permission to overwrite the file :(
Is there a way besides logging in as root?

jims
23rd November 2017, 11:43 PM
You might consider using one of the TTYs and logging in as root, completing what you need to do, then logging out and returning to TTY1 which contains your running graphics system.

srakitnican
24th November 2017, 12:02 AM
Thanks HaydnH,

echo is indeed still functional, the problem is that su and sudo are not, so I cannot get permission to overwrite the file :(
Is there a way besides logging in as root?

Hi, full path to a command should work.


$ /usr/bin/su -c "> /etc/environment"


Also, /etc/environment is not a shell script. See "man environment" on how to use it.