94

I recently had to upgrade to a VPS server (HostGator Linux) because I wanted to run a script that was a bit more complicated than the regular PHP db manipulation. I'm trying to install a JDK and Apache Ant (if it matters, for compiling Android Apps on server).

I watched tutorials on Linux Bash and started using it. I am currently trying to install Java (with JDK and JRE) on to the server.

I am following the tutorial on this page: http://www.oracle.com/technetwork/java/javase/install-linux-64-self-extracting-142068.html

However, I don't know what to do at this line:

  1. Download and check the download file size.

    You can download to any directory that you can write to.

How do I download Java from the command line?

If it matters, I am running CentOS v5.8

royhowie
  • 11,075
  • 14
  • 50
  • 67
user1893185
  • 1,053
  • 2
  • 8
  • 6
  • 7
    The third bullet point on [this page](http://stackoverflow.com/help/on-topic) states that questions about "software tools commonly used by programmers" are considered on-topic. Therefore, this question, being about Linux (which can be considered a tool, and is most definitely commonly used by programmers) is perfectly valid. If you disagree, please at least consider migrating the question to [Server Fault](http://serverfault.com/). – ethguo Jul 20 '14 at 22:31

3 Answers3

127

Using wget

wget -O /tmp/myfile 'http://www.google.com/logo.jpg'

or curl:

curl -o /tmp/myfile 'http://www.google.com/logo.jpg'
Ottavio Campana
  • 4,088
  • 5
  • 31
  • 58
imxylz
  • 7,847
  • 4
  • 28
  • 25
33

You can use the command wget to download from command line. Specifically, you could use

wget http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-x64.tar.gz

However because Oracle requires you to accept a license agreement this may not work (and I am currently unable to test it).

Alex DiCarlo
  • 4,851
  • 18
  • 34
  • 3
    Since the question is locked and I cannot post as an answer, I will write it as a comment. You can use `wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm"` to download. Of course you can change the URL to your needs. More can be found [here](https://www.digitalocean.com/community/tutorials/how-to-install-java-on-centos-and-fedora#install-oracle-java-8) – Murat Aykanat Jul 04 '17 at 13:41
2

I guess you could use curl and wget, but since Oracle requires you to check of some checkmarks this will be painfull to emulate with the tools mentioned. You would have to download the page with the license agreement and from looking at it figure out what request is needed to get to the actual download.

Of course you could simply start a browser, but this might not qualify as 'from the command line'. So you might want to look into lynx, a text based browser.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • 1
    I have also needed to do this (Linux noob). What I have done is to use Firefox (on my Win desktop) to accept the license then start download. As soon as the download starts, open the download dialog and cancel the download. Then rightclick on the cancelled item and choose "copy download link". You can now use this link in the `wget` command (paste it in the terminal window). – frIT Dec 07 '15 at 07:21