0
sudo tar -xvf $HOME/Desktop/Lesearch_Update/jdk-8u121-linux-x64.tar.gz  -C $HOME/Downloads/
sudo rm -r /usr/lib/jvm 
sudo mkdir -p /usr/lib/jvm/jdk1.8.0_121
sudo mv $HOME/Downloads/jdk1.8.0_121/* /usr/lib/jvm/java8/
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java8/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java8/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/java8/bin/javaws" 1
sudo echo '"JAVA_HOME=/usr/lib/jvm/java8"' >> /etc/profile
sudo echo 'PATH=$PATH:$HOME/bin:$JAVA_HOME/bin' >> /etc/profile
sudo echo 'export JAVA_HOME' >> /etc/profile
sudo echo 'export JRE_HOME' >> /etc/profile
sudo echo 'export PATH' >> /etc/profile
sudo rm -r $HOME/Downloads/jdk1.8.0_121
echo "java 8 installed sucessfully.... :) "
echo " "
echo " "
muru
  • 193,181
  • 53
  • 473
  • 722
  • *"but its not working"* is not a useful problem description. Start by reading [When using sudo with redirection, I get 'permission denied'](http://askubuntu.com/questions/230476/when-using-sudo-with-redirection-i-get-permission-denied) – steeldriver Mar 10 '17 at 17:52
  • Why a brittle 'installation script' instead of creating a real package? – user535733 Mar 10 '17 at 18:11
  • Try to add some more useful information such as the errors that you are getting when you execute the script. Otherwise it might become a lot of guess work. – akxer Mar 10 '17 at 18:25
  • tar: /home/vishal/Downloads/\r: Cannot open: No such file or directory tar: Error is not recoverable: exiting now – Vishal Kamble Mar 10 '17 at 18:45
  • 2
    Possible duplicate of [When using sudo with redirection, I get 'permission denied'](http://askubuntu.com/questions/230476/when-using-sudo-with-redirection-i-get-permission-denied) – Chai T. Rex Mar 10 '17 at 19:14
  • 1
    SOLVED !!!!! Used dos2unix command – Vishal Kamble Mar 11 '17 at 05:42
  • 2
    Possible duplicate of [Problem running the script in .sh file](http://askubuntu.com/questions/503300/problem-running-the-script-in-sh-file) – muru Mar 11 '17 at 06:36

1 Answers1

1

The immediate solution is to take sudo out of the script and run the script using sudo script-file.

A perhaps better solution is to use Web Upd8's package that takes care of installing Oracle's Java 8 for you, including updating it via apt upgrade when new versions come out.

This can be done in the terminal with:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Chai T. Rex
  • 5,126
  • 1
  • 24
  • 48