Manually Install JDK on Linux

This article applies to:

  • Platform(s): Xubuntu Linux
  • Java version: 22.0.2

Download

  1. Go to https://jdk.java.net and download the JDK version you want. For now, I choose JDK 22, and pick the download link for Linux/64 build, tar.gz format of JDK 22.0.2 General-Availability Release. So my downloaded file is openjdk-22.0.2_linux-x64_bin.tar.gz.
  2. Check the download file size and sha256 hash string to make sure that you have downloaded the full, uncorrupted file. For example, the jdk.java.net site reports that the Linux/x64 build file is 201996264 bytes, and the SHA256 hash string is 41536f115668308ecf4eba92aaf6acaeb0936225828b741efd83b6173ba82963
    xubuntu:~/share/download/java$ ls -l
    total 197264
    -rwxrwxrwx 1 root root 201996264 Aug 26 14:45 openjdk-22.0.2_linux-x64_bin.tar.gz
    xubuntu:~/share/download/java$ sha256sum openjdk-22.0.2_linux-x64_bin.tar.gz 
    41536f115668308ecf4eba92aaf6acaeb0936225828b741efd83b6173ba82963 openjdk-22.0.2_linux-x64_bin.tar.gz
    

Install

  1. I like to extract the JDK content to a temporary folder before moving/copying it to the default folder of /usr/lib/jvm.
    xubuntu:~/share/download/java$ mkdir ~/temp/jdk
    xubuntu:~/share/download/java$ tar -xvzf openjdk-22.0.2_linux-x64_bin.tar.gz -C ~/temp/jdk
    jdk-22.0.2/bin/jar
    jdk-22.0.2/bin/jarsigner
    jdk-22.0.2/bin/java
    jdk-22.0.2/bin/javac
    ... omitted-output ...
    jdk-22.0.2/lib/src.zip
    jdk-22.0.2/lib/tzdb.dat
    jdk-22.0.2/release
    xubuntu:~/share/download/java$ cd ~/temp/jdk
    xubuntu:~/temp/jdk$ ls -l
    total 4
    drwxrwxr-x 8 h0ward h0ward 4096 Aug 26 15:18 jdk-22.0.2
    
  2. Move the new JDK content to /usr/lib/jvm
    xubuntu:~/temp/jdk$ sudo mkdir /usr/lib/jvm
    xubuntu:~/temp/jdk$ sudo mv jdk-22.0.2/ /usr/lib/jvm
    xubuntu:~/temp/jdk$ ls -l /usr/lib/jvm
    total 4
    drwxrwxr-x 8 h0ward h0ward 4096 Aug 26 15:18 jdk-22.0.2
    

Configure

  1. Update environment variables to point to the newly installed JDK by editing the /etc/environment file.
    xubuntu:~/temp/jdk$ sudo nano /etc/environment
    
  2. Add JAVA_HOME variable, and JDK bin to PATH.
    JAVA_HOME="/usr/lib/jvm/jdk-22.0.2"
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/lib/jvm/jdk-22.0.2/bin"
    

XDG User Directories

Some Linux distro desktop environments use the xdg-user-dirs tool to manage user directories. It creates default directories and handle localization of the filenames.

Early in the login phase, xdg-user-dirs-update is run, which reads a configuration file (/etc/xdg/user-dirs.conf), and a set of default directories (/etc/xdg/user-dirs.defaults). It then creates localized versions of a set of default directories in the user’s home directory, and sets up a configuration file in $XDG_CONFIG_HOME/user-dirs.dirs (XDG_CONFIG_HOME defaults to ~/.config). Applications can then use these directory variables as default location for files.

Creating default directories

When xdg-user-dirs-update is executed, it will:

  • Create a local ~/.config/user-dirs.dirs configuration file.
  • Create a local ~/.config/user-dirs.locale configuration file used to set the default language locale
  • Enable the user service xdg-user-dirs-update.service by default, in order to keep user directories up to date by re-running this command at the beginning of each login session.

Creating custom directories

Both the local (~/.config/user-dirs.dirs) and global (/etc/xdg/user-dirs.defaults) configuration files use the format

XDG_<directory_name>_DIR="$HOME/<directory_name>"

for example:

XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"

It is therefore possible to specify custom folders. For example,

XDG_MUSIC_DIR="$HOME/Documents/Music"
XDG_PICTURES_DIR="$HOME/Documents/Pictures"
XDG_VIDEOS_DIR="$HOME/Documents/Videos"
XDG_DOWNLOAD_DIR="$HOME/temp"

Alternatively, it is also possible to specify custom folders using command line. For example, the following command will set the DOWNLOAD folder in the local configuration file.

xdg-user-dirs-update --set DOWNLOAD ~/temp

Querying configured directories

Once set, any user directory can be viewed with xdg-user-dirs. For example, the following command will show the location of the Download directory (which corresponds to the XDG_DOWNLOAD_DIR variable in the local configuration file:

xdg-user-dir DOWNLOAD

Disable XDG user directory management

Edit the global configuration file (/etc/xdg/user-dirs.conf), and change enabled=True to enabled=False.

To enable/disable XDG for a single user, copy the configuration file to ~/.config/user-dirs.conf, and set the enable option accordingly.

Showing Seconds in Windows Taskbar Clock

  1. Navigate to the following registry key
    Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced
  2. Look for the registry value named ShowSecondsInSystemClock. If it is not there, create a new DWORD (32-bit) Value by that name, and give it a value of 1.
    Name Type Data
    ShowSecondsInSystemClock REG_DWORD 0x00000001 (1)
  3. Logout and login again to see the change.

Install .NET Core SDK on elementary OS

At this writing, I’m running elementary OS 0.4.1 Loki, which is based on Ubuntu 16.04.2 LTS. (It is important to know the Ubuntu version, since the .NET Core SDK distribution has different source list for different Linux distros and versions.)

.NET Core SDK version: v2.1.301

  1. Go to the All .NET Download site of Microsoft at https://www.microsoft.com/net/download/all.
  2. Click the link to the SDK version you want. For example, 2.1 SDK (v2.1.301) downloads.
  3. Choose the link of the Linux distro and version you are using. For example, since I’m running elementary OS, I click on the Ubuntu 14.04 Instructions link.
  4. Follow the instruction on the page to register Microsoft key and repository, and to follow steps to install .NET SDK.

    In my case, since my connection to the internet is behind a proxy server, I first make sure that wget is using proxy (see this post about [wget proxy setting]).

    Register Microsoft key and package source

    I type in the following wget command to get the .deb package from Microsoft.

    ~$ wget https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
    --2018-06-27 11:03:08--  https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
    Connecting to 10.0.2.2:3128... connected.
    Proxy request sent, awaiting response... 200 OK
    Length: 2452 (2.4K) [application/octet-stream]
    Saving to: ‘packages-microsoft-prod.deb’
    
    packages-microsoft-prod.deb                                 100%[==========================================================================================================================================>]   2.39K  --.-KB/s    in 0s      
    
    2018-06-27 11:03:09 (469 MB/s) - ‘packages-microsoft-prod.deb’ saved [2452/2452]
    

    I then install the downloaded package

    ~$ sudo dpkg -i packages-microsoft-prod.deb
    Selecting previously unselected package packages-microsoft-prod.
    (Reading database ... 173634 files and directories currently installed.)
    Preparing to unpack packages-microsoft-prod.deb ...
    Unpacking packages-microsoft-prod (1.0-3) ...
    Setting up packages-microsoft-prod (1.0-3) ...
    

    Which does three things: 1) adds the Microsoft packages information to the source list; 2) adds the Microsoft key to the trusted list; and 3) sets root as the owner of the two added files. See directory listing below:

    ~$ ls -l /etc/apt/sources.list.d/
    total 16
    -rw-r--r-- 1 root root  56 Feb 14 10:56 appcenter.list
    -rw-r--r-- 1 root root 144 Feb 14 10:56 elementary.list
    -rw-r--r-- 1 root root  78 Nov 27  2017 microsoft-prod.list
    -rw-r--r-- 1 root root 152 Feb 14 10:56 patches.list
    ~$ ls -l /etc/apt/trusted.gpg.d
    total 4
    -rw-r--r-- 1 root root 641 Jan 23  2017 microsoft-prod.gpg
    

    Install .NET Core SDK

    Make sure that https download transport for APT is installed and up to date.

    ~$ sudo apt-get install apt-transport-https

    downloads the package lists from the repositories and updates them to get information on the newest versions of packages and their dependencies.

    ~$ sudo apt-get update

    Install .NET SDK Core 2.1

    ~$ sudo apt-get -y install dotnet-sdk-2.1

    At the end of the installation, you will see the following information…

    This software may collect information about you and your use of the software, and send that to Microsoft.
    Please visit http://aka.ms/dotnet-cli-eula for more information.
    Welcome to .NET Core!
    ---------------------
    Learn more about .NET Core: https://aka.ms/dotnet-docs
    Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli-docs
    
    Telemetry
    ---------
    The .NET Core tools collect usage data in order to help us improve your experience. The data is anonymous and doesn't include command-line arguments. The data is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
    
    Read more about .NET Core CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
    
    Configuring...
    --------------
    A command is running to populate your local package cache to improve restore speed and enable offline access. This command takes up to one minute to complete and only runs once.
    

    Verify that .NET Core 2.1 is installed

    ~$ dotnet --version
    2.1.301