Install JDK 1.8.0_74 in Linux

This is for 64-bit installation.

  1. Download JDK from Oracle site
    The installation file I use is jdk-8u74-linux-x64.tar.gz.
  2. Change directory to install the JDK code in /opt
    cd /opt
  3. extract the JDK files
    sudo tar -xvzf <location of downloaded JDK>/jdk-8u74-linux-x64.tar.gz 

    This will put the JDK into the newly created directory named jdk1.8.0_74

  4. Update environment variables to point to the newly installed JDK by editing the /etc/environment file.
    sudo nano /etc/environment

    Add the JAVA_HOME variable, and add JDK bin to the PATH variable.

  5. Refresh the environment variable.
    source /etc/environment
  6. Verify that the updated environment variables are in place and the path to the JDK is valid
    $ echo $JAVA_HOME
    $ echo $PATH
    $ javac -version
    javac 1.8.0_74
  7. Update Java alternative list. You want to set a higher priority for the new JDK. On my system this is the result when I query the alternatives:
    $ update-alternatives --verbose --query java
    Link: java
    Status: auto
    Best: /usr/lib/jvm/java-6-openjdk/jre/bin/java
    Value: /usr/lib/jvm/java-6-openjdk/jre/bin/java
    Alternative: /usr/lib/jvm/java-6-openjdk/jre/bin/java
    Priority: 1061
     java.1.gz /usr/lib/jvm/java-6-openjdk/jre/man/man1/java.1.gz

    So, let’s make the new JDK our default…

    sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_74/bin/java 18074

    The response is:

    update-alternatives: using /opt/jdk1.8.0_74/bin/java to provide /usr/bin/java (java) in auto mode.

    Now, when you type java -version, you will see

    java version "1.8.0_74"
    Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
  8. Likewise, set the new Java compiler as default with

    sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_74/bin/javac 18074
  9. If you are running Firefox, you can go on to link the new JRE plugin to your Mozilla plugins folder. See my other post on how to activate the JRE plugin for Firefox.

Set Up Proxy Environment Variables

Add the following one-liner at the end of .bashrc script:

export {http,https,ftp}_proxy='http://<user>:<password>@<proxy-server>:<port>'

For example: export {http,https,ftp}_proxy=''

For this to take effect, restart terminal or run source with . ~/.bashrc

After that, check for the presence of the environmental variables with printenv | grep proxy

yields the following output:


Adding Additional Workspaces to Ubuntu Desktop

Use the command:
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ {hsize | vsize} n

For example:

To set 3 horizontal workspaces…

gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize 3

To set 2 vertical workspaces…

gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ vsize 2

If combine the two commands above, you will have a total of 6 workspaces (3 columns and 2 rows).

OCR Text from PDF Document

Today, I had to convert a scanned 3-page PDF file back into a editable document. So, open source software to the rescue. I was able to complete the task with the help of:

  • tesseract — for OCR, and
  • imagemagick — for converting PDF pages to an image format that tesseract accepts.
  1. Installing the software

    sudo apt-get -y install tesseract-ocr imagemagick

  2. Convert PDF pages to image

    convert -density 300 -depth 8 scan.pdf[0] scan0.png
    convert -density 300 -depth 8 scan.pdf[1] scan1.png
    convert -density 300 -depth 8 scan.pdf[2] scan2.png

    convert is a member of the amagemagick tools. You can use it to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

    Here, I’m only using two options:

    -density width
    to set the resolution of an image for rendering to devices. The default unit of measure is dots per inch. The default resolution is 72 dpi.

    -depth value
    to set the number of bits in a color sample within a pixel.

    The numbers between the brackets mark the page in the PDF document to be converted. Of course, as any programmer can tell you, you start counting at zero.

  3. OCR page images to text

    $ tesseract scan0.png scan0.txt
    Tesseract Open Source OCR Engine v3.02.01 with Leptonica
    $ tesseract scan1.png scan1.txt
    Tesseract Open Source OCR Engine v3.02.01 with Leptonica
    $ tesseract scan2.png scan2.txt
    Tesseract Open Source OCR Engine v3.02.01 with Leptonica

And then just copy the OCR text from the text files into a new document to clear up any typo and reformat the document.