Speed up Java on your desktop Linux
Even though you may have substantial amount of RAM and SSD any Java based IDE will still feel sluggish under Linux. There is a reasonably simple way of dealing with this issue — place the JDK onto ram-disk.
Ubuntu 16.04 or more recent
Ubuntu 14.o4+ alredy contains fully usable ramdisk located at /dev/shm/. The idea here would be to copy the JDK from it’s disk location onto /dev/shm/ whenever system starts since whatever was stored there goes away after shutdown.
Since we have systemd let’s utilize it to make things easier:
In some text editor create this content:
[Unit]
Description=JDK to RAMDISK
Requires=local-fs.target
After=local-fs.target[Service]
Type=oneshot
ExecStart=/bin/cp -ru /usr/lib/jvm/java-8-openjdk-amd64/ /dev/shm/[Install]
WantedBy=multi-user.target
Replace the path to JDK if it is different (and most likely it is) and save the file as jdk-ramdisk.service.
Now install the newly created oneshot service:
sudo cp -uv /path/to/jdk-ramdisk.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable jdk-ramdisk.service
If you want to configure this JDK as default do this:
echo ‘export JAVA_HOME=/dev/shm/path/to/jdk’ | sudo tee -a /etc/environment
If it is for specific IDE like PHPStorm this will also do:
echo ‘export PHPSTORM_JDK=/dev/shm/path/to/jdk’ >> ~/.profile
Restart the machine and enjoy the speedup