Q: Setting Java environmental variables on Centos 7 breaks the $PATH After installing Java 8 on a Centos 7 server I added the following lines to /etc/environment
export JAVA_HOME=/opt/jdk1.8.0_161
export JRE_HOME=/opt/jdk1.8.0_161/jre
export PATH=$PATH:/opt/jdk1.8.0_161/bin:/opt/jdk1.8.0_161/jre/bin

However after a restart on the box, after I login it comes up with 
-bash: id: command not found
-bash: id: command not found
-bash: id: command not found
/usr/libexec/grepconf.sh: line 5: grep: command not found

This makes me think I have broken the PATH variable somehow, but I cannot open /etc/environment as "less", "vi" and etc are not recognised as commands.
And ideas on that I did wrong and how do I fix the current state?

A: Don't export in /etc/environment. Instead, provide only the definitions, such as JAVA_HOME=/opt/jdk1.8.0_161.
Use the full path to vi, such as /usr/bin/vi to fix the file. This way PATH (which is exported in the now failing /etc/environment) won't be searched.
Here is an example command.
/usr/bin/sudo /usr/bin/vi /etc/environment

