I am new hand in Linux OS. So I hope my experience can help people in similar conditions.
First, of course, you need to install Java Development Kit (JDK) into your ubuntu since it is not defauly installed.
The command I used is:
apt-cache search jdk (# then I can choose what version of JDK I want to install. E.g. openJDK-1.7) sudo apt-get install openJDK-1.7 (# then OpenJDK 1.7 will be installed to default path : usr/lib/jvm) (# more than 1 folder will be created under "usr/lib/jvm", but not all of them is valid "JDK".) (# so you need to enter the "bin" folder to check whether it is JDK (containing JAVAC) or normal JRE) (# since I installed openJDK, which does not include VisualVM automatically, so I need to download and install VisualVM manually)
java –version (# make sure the path is correct, and “JDK” reveals in the path) (# if your installation of JAVA failed, you cannot get correct response by this command)
Second, it is time to install VisualVM.
VisualVM is free and open source software. If you install Sun-JDK, it is already binded. If you installed open-JDK like me, you need to download and install it independently.
sudo apt-cache search visualvm (# now make sure you can download VisualVM from your software repository) (# if there is not any visualVM in your current repository, you need to search internect to learn how to add new repository) sudo apt-get install visualvm (# Then visualVM will be installed to default path. In my machine, it is "usr/lib/visualVM")
After installation, the main code and resources of VisualVM can be found in default installation path (in my PC, it is “usr/lib/visualVM”), and the short cut start file (“jvisualvm”) will be created in “usr/lib”.
Third, before you directly run VisualVM, you MUST edit the auto-generated script file “jvisualvm” to match the java environment.
I hate using VI in Linux because I cannot remember hotkeys. So I installed leafpad (a simple notepad software) to edit txt files.
apt-cache search 'notepad*' (# here I found 'leafpad' available in my repository, so I installed it) sudo apt-get install leafpad
sudo chmod +w /usr/lib/jvisualvm (# use this command to change script file from “Readonly” mode to “Read & Write Mode”) sudo leafpad /usr/lib/jvisualvm (# use this command to invoke leafpad, to edit the content of script file -- jvisualvm)
The default content of script file MUST be changed, unless you cannot launch VisualVM successfully.
There is a section of code (as follows) in the file. (maybe starts from line 12). It means that the system checks all given paths (from [path1] to [path n]), if any path includes file “javac” in sub-folder “[path]/bin”, then VisualVM will use this path as “jdkhome”.
jdkhome= for j in [path1] [path2] ... [path n]; do if [-x $j/bin/javac ]; then jdkhome=$j break; fi done
WHEN YOU INSTALL VISUALVM, the content of this script file will not be updated according to your own JAVA ENVIRONMENT.
so I changed the this section of code as follows to solve the problem (by inserting my JDK path into condition part):
jdkhome= for j in /usr/lib/jvm/openJDK-1.7 [path 1] [path 2] ... [path n]; do if [-x $j/bin/javac ]; then jdkhome=$j break; fi done
DO NOT FORGET TO REOPEN THE FILE TO CHECK YOUR CHANGE!
Now, you can successfully invoke VisualVM.