title: Install Java7 on Ubuntu 16.04 through bash script
body: <p>I have below function <code>java_install</code> written in a bash script to install <code>java</code> on Linux box, to which I pass <code>jdk-1.7.0_80-linux-x64.tgz</code> as <code>JAVA_PACKAGE</code>.
  Now what is happening is java gets installed and works fine only within the script. Once I come out of this script, none of the java functionalities work, not even <code>java -version</code>. Could someone please help me on what I might be missing here? Basically, I just want java to be installed permanently on this box once this script is executed.</p>
  
  <pre><code>java_install() {
  local JAVA_PACKAGE=$1
  local TMPDIR=/tmp/quickstart
  local TARGET=/usr/share
      if [ -n "$JAVA_PACKAGE" ] &amp;&amp; [ -f "$JAVA_PACKAGE" ]; then
    rm -rf $TMPDIR
    mkdir -p $TMPDIR
    cp $JAVA_PACKAGE $TMPDIR
    ( cd $TMPDIR &amp;&amp; tar fxz $JAVA_PACKAGE &amp;&amp; rm $JAVA_PACKAGE )
    local JAVA_BASENAME=$(ls -1 $TMPDIR)
    mkdir -p $TARGET
    if [ -d "$TARGET/$JAVA_BASENAME" ]; then
      echo "# Java already installed at $TARGET/$JAVA_BASENAME"
      log_info "Java already installed at $TARGET/$JAVA_BASENAME"
    else
      echo "# Java now installed at $TARGET/$JAVA_BASENAME"
      log_info "Java now installed at $TARGET/$JAVA_BASENAME"
      mv $TMPDIR/$JAVA_BASENAME $TARGET
    fi
    rm -rf $TMPDIR
  
    # now create a script to export these settings
    export JAVA_HOME=$TARGET/$JAVA_BASENAME
    export PATH=$JAVA_HOME/bin:$PATH
  else
    echo "# cannot find java package to install"
    log_error "cannot find java package to install"
  fi
  } 
  </code></pre>