Software & AppsOperating SystemLinux

How To Fix Pycharm “No JDK found” Error on Ubuntu

Ubuntu 21

In this article, we will be addressing a common issue faced by many Pycharm users on Ubuntu: the “No JDK found” error. This error typically occurs when Pycharm is unable to locate the Java Development Kit (JDK) on your system. The JDK is essential for running and debugging your Java programs in Pycharm.

Quick Answer

To fix the "No JDK found" error in Pycharm on Ubuntu, you can try modifying the Pycharm.sh file, modifying the environment variables, or installing Pycharm via Snap.

Understanding the Error

Before we delve into the solutions, it’s crucial to understand what the error message means. When you attempt to start Pycharm, you might encounter an error message that reads “No JDK found”. This implies that Pycharm is unable to find the JDK on your system, which is required for it to function correctly.

Prerequisites

Before proceeding with the solutions, ensure that you have JDK installed on your system. You can check this by opening your terminal and typing java -version. If the JDK is installed, you should see the version of your installed JDK. If not, you will need to install it.

Solutions

Solution 1: Modifying the Pycharm.sh File

  1. Open your terminal and type the following command: sudo gedit /usr/share/pycharm/bin/pycharm.sh. This command opens the pycharm.sh file in gedit, a text editor. If you prefer using a different text editor, replace gedit with the name of your preferred editor.
  2. In the opened file, locate the line: JDK=update-alternatives --list java | grep java-8 | sed 's,jre/bin/java,,'. This line is trying to find the location of your JDK.
  3. Replace the line with either JDK='/usr/lib/jvm/java-8-oracle/' or JDK='/usr/lib/jvm/java-8-openjdk-amd64/' depending on your installed JDK version.
  4. Save the changes and close the text editor.
  5. Try running Pycharm again. The error should be resolved.

Solution 2: Modifying the Environment Variables

  1. Open your terminal and type nano ~/.bashrc or nano ~/.profile. This command opens the .bashrc or .profile file in nano, a command-line text editor.
  2. Add the following lines at the end of the file:
    export PYCHARM_JDK=$JAVA_HOME
    export PYSPARK_SUBMIT_ARGS="--master local[2] pyspark-shell"
    These lines set the PYCHARM_JDK environment variable to the path of your JDK and configure PySpark to use two local cores.
  3. Save the changes and close the text editor.
  4. Restart your terminal or type source ~/.bashrc or source ~/.profile to apply the changes.
  5. Try starting Pycharm again. The error should be resolved.

Solution 3: Installing Pycharm via Snap

If the above solutions do not work, you can try installing Pycharm via Snap. Snap is a package manager for Linux that makes it easy to install applications and their dependencies.

  1. Open your terminal and type sudo snap install pycharm-community --classic. This command installs the community edition of Pycharm.
  2. Start Pycharm for the first time by typing pycharm-community in the terminal.
  3. After closing Pycharm, you can find it in the dash and drag its icon to the launcher for easy access.

We hope this article has helped you resolve the “No JDK found” error in Pycharm on Ubuntu. If you’re still encountering issues, please refer to the official Pycharm documentation or the Ubuntu community help pages.

How do I check if JDK is installed on my Ubuntu system?

To check if JDK is installed on your Ubuntu system, open your terminal and type java -version. If JDK is installed, you should see the version of your installed JDK. If not, you will need to install it.

Can I use a different text editor to modify the Pycharm.sh file?

Yes, you can use a different text editor to modify the Pycharm.sh file. Instead of sudo gedit /usr/share/pycharm/bin/pycharm.sh, you can replace gedit with the name of your preferred text editor.

How do I modify the environment variables in Ubuntu?

To modify the environment variables in Ubuntu, open your terminal and type nano ~/.bashrc or nano ~/.profile to open the .bashrc or .profile file in nano, a command-line text editor. Add or modify the required environment variables, save the changes, and either restart your terminal or type source ~/.bashrc or source ~/.profile to apply the changes.

What is Snap and how does it help in installing Pycharm?

Snap is a package manager for Linux that simplifies the installation of applications and their dependencies. By using Snap, you can easily install Pycharm on your Ubuntu system by running the command sudo snap install pycharm-community --classic.

Leave a Comment

Your email address will not be published. Required fields are marked *