The preferred way of installing Eclipse in Ubuntu is to go to the official Eclipse site, download the package and manually install it. The reason being that the official apt repository might not have the latest version in it.
Once you get to https://www.eclipse.org/downloads/ click on the Download button to download the tar.gz file. Assuming that you are already on Ubuntu, the Eclipse website will auto-detect the OS and provide the correct download file
Once the file is downloaded, unzip it into a folder. Preferably create a folder within your
~/Downloads folder so that you have complete access to it.
Using the terminal change the current directory to the unzipped folder. eg.
~/Downloads/eclipse-installer and type
sudo ./eclipse-inst to start the installer
By default the installer will start in Simple mode. We do not want to use the Simple mode because it puts everything under root. Later on you will not be able to launch Eclipse using your current user name. So click on the hamburger icon on the top right corner of the installer and choose Advanced Mode
In the Product screen, at the bottom of the screen, uncheck Bundle Pool and make sure the Java VM folder is pointing to the correct folder in case you have multiple java versions installed.
Click Next. Click Next again on the Projects screen. In the Variables screen, accept the default folder name or change it if you want. Finally on the Confirmation screen, click Finish.
Once the installer finishes running it will launch the IDE and ask you to choose your default Workspace folder. Thereafter it will complete the launch. At this stage you can close Eclipse.
Basically what we have done, is to make sure that Eclipse runs as the current user and does not put anything in the root folder. We need to create a desktop icon for easy access as the installer does not do this automatically in Ubuntu.
Go to the ~/Desktop folder and use your favorite editor to create a file
eclipse.desktop . Put the following contents and save it
Comment=Eclipse Integrated Development Environment
We will give it executable rights with the command:
mod +x ~/Desktop/eclipse.desktop
Double clicking on the desktop icon should now launch Eclipse without any problems.