Introduction to STM32CubeMX
STM32CubeMX is a versatile graphical configuration tool developed by STMicroelectronics specifically for STM32 microcontroller projects. It simplifies the setup and initialization process by allowing developers to configure various aspects such as pins, clocks, peripherals, and middleware through a user-friendly interface. In addition, STM32CubeMX generates the necessary initialization code for STM32CubeIDE or other supported toolchains, streamlining the development workflow and making it easier to implement complex functionalities in embedded applications. By reducing the complexity of microcontroller configuration, STM32CubeMX empowers developers to focus more on code development and innovation.
Installing STM32CubeMX on Ubuntu is usually straightforward, but recent versions of STM32CubeMX may fail if the correct Java Runtime Environment is not available. This article explains how to install STM32CubeMX on Ubuntu 22.04 and how to solve the Java runtime errors that can appear during installation.
System Used
The installation steps below were tested on:
Ubuntu 22.04 LTSSTM32CubeMX 6.17.0OpenJDK 21
Although STM32CubeMX may initially report that it requires Java JRE 17.0.6 or later, STM32CubeMX 6.17.0 may require Java 21 in practice, depending on the installer package.
Step 1: Install Required Packages
First, update the package list and install the basic utilities required for installation:
sudo apt updatesudo apt install unzip
The STM32CubeMX installer is normally downloaded as a compressed file, so unzip is required to extract it.
Step 2: Install Java
STM32CubeMX is a Java-based application, so a suitable Java Runtime Environment is required.
Initially, you may try installing Java 17:
sudo apt install openjdk-17-jre
Check the installed Java version:
java -versionwhich java
Example output:
openjdk version "17.0.19"OpenJDK Runtime EnvironmentOpenJDK 64-Bit Server VM/usr/bin/java
However, with STM32CubeMX 6.17.0, Java 17 may still not be sufficient. If the installer reports an error similar to this:
java.lang.UnsupportedClassVersionError:class file version 65.0, this version of the Java Runtime only recognises...
then Java 21 is required.
Install Java 21:
sudo apt install openjdk-21-jre
Then configure the default Java version:
sudo update-alternatives --config java
Select the option pointing to:
/usr/lib/jvm/java-21-openjdk-amd64/bin/java
Now verify the active Java version:
java -version
Expected output should show Java 21:
openjdk version "21..."
Step 3: Download STM32CubeMX
Download STM32CubeMX for Linux from the official STMicroelectronics website.
The downloaded file will usually have a name similar to:
en.stm32cubemx-lin-v6-17-0.zip
After downloading, go to your Downloads directory:
cd ~/Downloads
Extract the package:
unzip en.stm32cubemx*.zip
After extraction, you should see the installer file:
SetupSTM32CubeMX-6.17.0
Make it executable:
chmod +x SetupSTM32CubeMX-6.17.0
Step 4: Run the Installer
Try running the installer:
./SetupSTM32CubeMX-6.17.0
At this point, you may see an error such as:
Please install Java JRE 17.0.6 or a more recent version
This can happen even when Java 17 or Java 21 is already installed correctly.
The reason is that the STM32CubeMX installer first searches for Java in relative locations near the installer file, such as:
./jre/bin/java../jre/bin/java../../jre/bin/java../../../jre/bin/java
It may not use /usr/bin/java directly.
Step 5: Create a Clean Installation Directory
To avoid confusion with old or incompatible Java folders in the Downloads directory, create a clean installation directory:
mkdir -p ~/stm32cubemx_installcp ~/Downloads/SetupSTM32CubeMX-6.17.0 ~/stm32cubemx_install/cd ~/stm32cubemx_install
Now create a local jre symbolic link that points to the installed Java 21 runtime:
ln -s /usr/lib/jvm/java-21-openjdk-amd64 jre
Check that the installer can now find Java:
ls -l jre/bin/java
You should see that jre/bin/java points to the Java 21 executable.
Now run the installer again:
./SetupSTM32CubeMX-6.17.0
This time, the installer should start successfully.
Step 6: Complete the Graphical Installation
Once the installer opens, follow the graphical installation wizard.
You can choose a user-local installation path or a system-wide installation path. For most development machines, a user-local installation is usually sufficient.
After installation, STM32CubeMX can be launched from the application menu or from the installation directory.
Common Problem: Local jre Folder in Downloads
One common issue is the presence of an old jre directory in the same folder as the installer.
For example:
cd ~/Downloadsls -ld jre
If this shows a directory such as:
drwxr-xr-x 8 user user 4096 jre
then the STM32CubeMX installer may try to use this local Java runtime instead of the system Java.
You can rename it safely:
mv jre jre_old
Then try running the installer again.
However, for STM32CubeMX 6.17.0, the cleaner solution is to use a separate installation directory and explicitly provide the Java 21 runtime using a symbolic link:
cd ~/stm32cubemx_installrm -rf jreln -s /usr/lib/jvm/java-21-openjdk-amd64 jre./SetupSTM32CubeMX-6.17.0
Final Working Command Sequence
The final successful installation sequence is:
sudo apt updatesudo apt install unzip openjdk-21-jresudo update-alternatives --config javajava -versionmkdir -p ~/stm32cubemx_installcp ~/Downloads/SetupSTM32CubeMX-6.17.0 ~/stm32cubemx_install/cd ~/stm32cubemx_installrm -rf jreln -s /usr/lib/jvm/java-21-openjdk-amd64 jre./SetupSTM32CubeMX-6.17.0
Why Java 21 May Be Required
If you see an error mentioning:
class file version 65.0
that means the Java class file was compiled for Java 21.
In simple terms, the installer is trying to run code built with a newer Java version than the runtime currently being used. Java 17 cannot run Java 21 class files. Installing Java 21 and ensuring the installer uses it solves the issue.
Conclusion
Installing STM32CubeMX on Ubuntu 22.04 is simple once the Java runtime issue is understood. The main point is that STM32CubeMX 6.17.0 may not use the system Java automatically. It searches for a local jre directory near the installer, so creating a symbolic link named jre pointing to Java 21 allows the installer to run correctly.
For STM32CubeMX 6.17.0 on Ubuntu 22.04, the most reliable approach is:
ln -s /usr/lib/jvm/java-21-openjdk-amd64 jre
inside the directory containing the installer.
Once this is done, the STM32CubeMX installer should launch normally and complete the installation.
Discover more from Tech For Talk
Subscribe to get the latest posts sent to your email.
Leave a Reply