Skip to content

Instantly share code, notes, and snippets.

@128keaton
Last active November 8, 2019 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 128keaton/25ddf859289a4dc13a675b5d3898356d to your computer and use it in GitHub Desktop.
Save 128keaton/25ddf859289a4dc13a675b5d3898356d to your computer and use it in GitHub Desktop.
Small scripts I use to run IntelliJ IDEA inside of WSL2 with an X11 server

1. Create ramdisk in /etc/fstab:

Open up a shell instance editing /etc/fstab:

$ sudo nano /etc/fstab

Inside the editor, append the following to create a new ramdisk. Adjust the 1024M segment to whatever size you want your ramdisk to be.

tmpfs /tmp/ramdisk tmpfs noexec,defaults,noatime,size=1024M,x-gvfs-show,mode=1777 0 0

Next, initialize the ramdisk by running the following:

$ sudo mount -a

2. Create ramdisk folders for your IntelliJ IDEA install:

Inside a shell instance, type the following:

$ sudo nano /usr/lib/tmpfiles.d/intellij.conf

Inside the new buffer, append the following:

d /tmp/ramdisk/intellij/caches 0777 root root — -
d /tmp/ramdisk/intellij/index 0777 root root — -

3. Symlink the IntelliJ IDEA index/cache folders:

Make sure no instance of IntelliJ IDEA is running when you run these commands

To get the configuration folder for your current install of IntelliJ IDEA, run the following in the shell:

$ cd ~/ &&  ls -la | grep .IntelliJ

Your output should look like the following:

drwxr-xr-x  4 keatonburleson keatonburleson  4096 Nov  7 13:00 .IntelliJIdea2019.2

This lets us know that we have our configuration stored in ~/.IntelliJIdea2019.2

Next, inside the shell, run the following (replacing .IntelliJIdea2019.2 with your version determined above):

$ ln -s /tmp/ramdisk/intellij/caches ~/.IntelliJIdea2019.2/system/caches
$ ln -s /tmp/ramdisk/intellij/index ~/.IntelliJIdea2019.2/system/index 

4. Done!

You should be good to go!

#!/bin/bash
cd ~/
FIND_PATTERN=".IntelliJIdea*"
INSTALL_DIRS=( $FIND_PATTERN )
FULL_PATH=$(readlink -f ${INSTALL_DIRS[-1]})
SYS_PATH="${FULL_PATH}/system"
CACHES_PATH="${SYS_PATH}/caches"
INDEX_PATH="${SYS_PATH}/index"
echo "Correcting permissions at '${SYS_PATH}'"
sudo chmod 777 ${CACHES_PATH}
sudo chmod 777 ${INDEX_PATH}
#!/bin/bash
APP_DIR=$(ls -td ~/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/*/ | head -1)
IDEA_LAUNCH="${APP_DIR}/bin/idea.sh"
WIN_IP=$(grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /etc/resolv.conf)
export DISPLAY="${WIN_IP}:0"
(
trap - SIGINT
exec /bin/bash $IDEA_LAUNCH "$@"
) > /dev/null 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment