Advertisement
ak47suk1

manually install jdk

Oct 1st, 2010
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.81 KB | None | 0 0
  1. [Tutorial] Manually installing the JDK 6 Update XX
  2.  
  3.  
  4. 1) Introduction
  5.  
  6. This tutorial is meant to help someone install the latest version of the JDK, currently the JDK 6 Update 13. Included in the tutorial is the installation of the JDK itself, as well as installation of the included JRE and Java Web Plugin for Firefox. The instructions may work for other versions of the JDK. Please use your own discretion when deciding whether to use this tutorial with other versions of the JDK. It should be noted that this tutorial also deals with the installation of the new 64 bit Java Web Plugin.
  7.  
  8. Also please note that this tutorial is meant to be very user friendly. If you are an advanced user you should be able to skim through in five minutes and get everything working.
  9.  
  10. If you have anything to add please post away.
  11.  
  12. 2) Uninstallation of the current JDK/JRE/Web Plugin
  13.  
  14. 2.1)Uninstallation of the current Sun JDK/JRE/Web Plugin
  15.  
  16. If you have the currently have the Sun JDK installed you need to remove it. Use the following command in the terminal:
  17.  
  18. Note: If you are currently using some or all of these packages please note down which ones so you can revert if need be.
  19.  
  20. Code:
  21. sudo apt-get remove sun-java6-jre sun-java6-jdk sun-java6-bin
  22. If you installed the Sun Java Web Plugin and made it default you will have to remove it as well using the terminal command:
  23.  
  24. Note: If you are currently using this package please note it down so you can revert if need be.
  25.  
  26. Code:
  27. sudo apt-get remove sun-java6-plugin
  28.  
  29. Note: If you made the Sun Java Web Plugin default you will either have to make the IcedTea Java Web Plugin default (not covered here) or make the new Sun Java Web Plugin default (covered in the optional section "Setting up the Java Web Plugin").
  30.  
  31. 2.2) (Optional) Uninstallation of the OpenJDK/JRE/IcedTea Web Plugin
  32.  
  33. By default Ubuntu comes with the OpenJDK JRE, IcedTea Java Web Plugin and a few other dependant packages. If you leave these packages and do not complete any of the optional sections these packages will still be used by default in everything but the terminal. However, if you are like me and do not want multiple versions of Java lying around taking up hard disk space then you can remove them using the following terminal command:
  34.  
  35. Note: You will not necessarily have all these packages installed. If you are missing some please note down which ones so you can revert properly if need be.
  36.  
  37. Code:
  38. sudo apt-get remove openjdk-6-jre openjdk-6-jre-headless icedtea-6-jre-cacao icedtea6-plugin default-jre default-jre-headless icedtea-gcjwebplugin
  39.  
  40. 2.3) Removal of unnecessary packages
  41.  
  42. Everything should have been uninstalled correctly. However, to make sure we do not have any additional unused packages around that we no longer need, type the following in the terminal:
  43.  
  44. Code:
  45. sudo apt-get autoremove
  46.  
  47. 3) Download of the correct JDK bin file
  48.  
  49. Go to http://java.sun.com/javase/downloads/index.jsp in your browser. On this page the current JREs and JDKs are listed along with some other tools. This tutorial was built for the the JDK 6 Update 13. However, it will probably work for newer/older updates of the 6 series as well. If there is a newer JDK available you may want to grab it and adapt the tutorial.
  50.  
  51. After choosing the appropriate JDK click on the download link next to it. If you use i386 (32 bit) Ubuntu you will want to download the “Linux” version on the next page, however if you are on amd64 (64 bit) Ubuntu you will want to download the “Linux x64” version.
  52.  
  53. Once the JDK file (jdk<something>.bin) has finished downloading you need to move it to your home directory.
  54.  
  55. 4) Extract and install the bin file
  56.  
  57. Open a terminal and type the following commands:
  58.  
  59. Code:
  60. chmod +x jdk*.bin
  61. sudo ./jdk*.bin
  62. Before the bin file will extract you have to agree to the terms and conditions (by typing yes or no). To skip through the agreement simply press q.
  63.  
  64. Now you have an extracted JDK directory (with root ownership) in your home directory. Now we need to move it to somewhere a little more appropriate. I moved mine to /usr/local/. If you are an advanced user you can pretty much put in anywhere you want. Just make sure you adapt the tutorial accordingly.
  65.  
  66. At this point please note down the name of the JDK folder in your home folder, you will need to type it in for later commands. For me the name of the folder is :
  67.  
  68. Code:
  69. jdk1.6.0_13
  70. Henceforth the folder will be refered to as <JAVA_FOLDER>. If you see <JAVA_FOLDER> in any of the commands replace it with the folder name.
  71.  
  72. To move the JDK folder to /usr/local/ type the following in the terminal.
  73.  
  74. Code:
  75. sudo mv <JAVA_FOLDER>/ /usr/local/
  76. 5) Setting up the JAVA_HOME and PATH variables
  77.  
  78. In order to use the various Java terminal commands (such as java & javac) with the JDK that we just installed the JAVA_HOME and PATH variables need to be set. This involves editing a text file, however, you have to edit a different text file depending on whether you want to set up the variables system wide or just for an individual user.
  79.  
  80. Please note down which file you edited in case the settings need to be removed.
  81.  
  82. 5.1) Settings the variables up system wide
  83.  
  84. To set the variables up system wide either the /etc/profile file or the /etc/bash.bashrc need to be edited. The difference between these files is that the former is loaded once when you log in, whereas the latter is loaded every time time you start a new terminal.
  85.  
  86. Please be careful when adding the PATH line. If you execute the command without the $PATH: part then your terminal will stop working properly.
  87.  
  88. To edit the /etc/profile file type the following in the terminal:
  89.  
  90. Code:
  91.  
  92. sudo -i
  93. echo "export JAVA_HOME=/usr/local/<JAVA_FOLDER>/bin/java" >> /etc/profile
  94. echo "export PATH=$PATH:/usr/local/<JAVA_FOLDER>/bin" >> /etc/profile
  95. exit
  96. Note: It is important to type exit here.
  97.  
  98. Alternatively, to edit the /etc/bash.bashrc file type the following in the terminal:
  99.  
  100. Code:
  101.  
  102. sudo -i
  103. echo "export JAVA_HOME=/usr/local/<JAVA_FOLDER>/bin/java" >> /etc/bash.bashrc
  104. echo "export PATH=$PATH:/usr/local/<JAVA_FOLDER>/bin" >> /etc/bash.bashrc
  105. exit
  106. Note: It is important to type exit here.
  107.  
  108. If you accidentally added an incorrect PATH variable press alt+f2, type: gksudo nautilus, navigate to the /etc directory and remove the offending line (at the bottom of the file) using a text editor.
  109.  
  110. 5.2 Settings the variables up for a single user
  111.  
  112. To set the variables for a single user the $HOME/.profile file or $HOME/.bashrc file need to be edited. The difference between these files is that the former is loaded once when you log in, whereas the latter is loaded every time time you start a new terminal.
  113.  
  114. To edit the $HOME/.profile file type the following in the terminal:
  115.  
  116. Code:
  117.  
  118. echo "export JAVA_HOME=/usr/local/<JAVA_FOLDER>/bin/java" >> $HOME/.profile
  119. echo "export PATH=$PATH:/usr/local/<JAVA_FOLDER>/bin" >> $HOME/.profile
  120. Alternatively, to edit the $HOME/.bashrc file type the following in the terminal:
  121.  
  122. Code:
  123.  
  124. echo "export JAVA_HOME=/usr/local/<JAVA_FOLDER>/bin/java" >> $HOME/.bashrc
  125. echo "export PATH=$PATH:/usr/local/<JAVA_FOLDER>/bin" >> $HOME/.bashrc
  126. If you accidentally added an incorrect PATH variable open your home folder, press ctrl.h and remove the offending lines (at the bottom of the file) using a text editor.
  127.  
  128. 5.3) Testing the changes
  129.  
  130. Depending on the file that you edited you will either have to start a new terminal or log in and out for the changes to take effect. Once you have either logged in and out or started a new terminal test the java commands that you use to see if they are working. If they are not something has gone wrong with the installation.
  131.  
  132. 5.4) A point of interest
  133.  
  134. If you complete the (optional) section "Setting up the default JRE" this section may not actually be necessary for use of the java command. However, it is necessary for any other commands you want to use, such as javac.
  135.  
  136. 6) (Optional) Setting up the default JRE
  137.  
  138. If you decided to remove the default JRE (OpenJDK JRE) this section is necessary for Java applications to run correctly. However, if you want to keep the OpenJDK as default do not do this section.
  139.  
  140. To set up the new JRE as default type the following in the terminal:
  141.  
  142. Code:
  143. sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/<JAVA_FOLDER>/jre/bin/java" 1
  144. sudo update-alternatives --set java /usr/local/<JAVA_FOLDER>/jre/bin/java
  145.  
  146. 7) (Optional) Setting up the Java Web Plugin
  147.  
  148.  
  149. If you removed the OpenJDK JRE and the IcedTea Java Web Plugin you need to complete this section for Java applets to work in your browser. However, if you left the OpenJDK JRE and IcedTea Java Web Plugin you may want to skip this section.
  150.  
  151. The commands are different for the i386 and amd64 architectures. Please follow the 32 bit section if you have Ubuntu i386 and the 64 bit version if you have Ubuntu amd64.
  152.  
  153. Just in case the following does not work please write down the original settings in the about:config section.
  154.  
  155. 7.1) 32 bit
  156.  
  157. Code:
  158. sudo mkdir /usr/lib/mozilla/plugins
  159. sudo ln -s /usr/local/<JAVA_FOLDER>/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins/
  160. Now restart Firefox, Open Tools > Add-ons > Plugins and enable libjavaplugin_oji. If you are still having problems with Java applets complete the following steps:
  161.  
  162. Type the following into the Firefox URL input box:
  163.  
  164. Code:
  165. about:config
  166. Next click agree. In the search box at the top on the next page type in java. Somewhere in this list is an entry for java.java_plugin_library_name. You must change this to:
  167.  
  168. Code:
  169. libjavaplugin_oji
  170. In the same list there is an entry for java.default_java_location_others. You must change this to:
  171.  
  172. Code:
  173. /usr/local/<JAVA_FOLDER>/jre/
  174. 7.2) 64 bit
  175.  
  176. Code:
  177. sudo mkdir /usr/lib/mozilla/plugins
  178. sudo ln -s /usr/local/<JAVA_FOLDER>/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins/
  179. Now restart Firefox, Open Tools > Add-ons > Plugins and enable libnpjp2. If you are still having problems with Java applets complete the following steps:
  180.  
  181. Type the following into the Firefox URL input box:
  182.  
  183. Code:
  184. about:config
  185. Next click agree. In the search box at the top on the next page type in java. Somewhere in this list is an entry for java.java_plugin_library_name. You must change this to:
  186.  
  187. Code:
  188. libnpjp2
  189. In the same list there is an entry for java.default_java_location_others. You must change this to:
  190.  
  191. Code:
  192. /usr/local/<JAVA_FOLDER>/jre/
  193. 8) Reversion
  194.  
  195. In order to revert to the please follow the following steps.
  196.  
  197. 8.1) Uninstallation of the new Sun JDK
  198.  
  199. To remove the folder for the new Java Sun JDK you need to type the following in the terminal:
  200.  
  201. Code:
  202. sudo rm -r /usr/local/<JAVA_FOLDER>/
  203. 8.2) Removal of the PATH and JAVA_HOME variables
  204.  
  205. You now need to remove the settings from the file you edited when you set these variables. If you edited one of the files in your home folder you need to do the following:
  206.  
  207. Open the home folder in the file browser, press ctrl.h (reveal hidden files) and open the correct file in a text editor. Then remove the lines that you added (down the bottom of the file).
  208.  
  209. If you edited one of the files in the /etc directory you need to press alt+f2, type gksudo nautilus and press enter. Now navigate to the /etc directory, open the correct file in a text editor and remove the lines that you added.
  210.  
  211. 8.3) Install the previous versions of the JDK/JRE/Web Plugin
  212.  
  213. To install the versions of the JDK/JRE/Web Plugin that you had before you need to complete the section "2) Uninstallation of the current JDK/JRE/Web Plugin" in reverse. Rather than typing:
  214.  
  215. Code:
  216. sudo apt-get remove <package1> <package2>...
  217. In the terminal. You need to type:
  218.  
  219. Code:
  220. sudo apt-get install <package1> <package2>...
  221. Please do not simply copy and paste the commands from the uninstallation section and change remove to install. If you remember I said note down the packages that you actually had installed in that section. Please only install the packages that you actually had before.
  222.  
  223. 8.4) (Optional) Set up the previous JRE as default
  224.  
  225. If you set up the new Sun Java JRE as default you will need to complete this step to revert.
  226.  
  227. To complete this step type the following in the terminal:
  228.  
  229. Code:
  230. sudo update-alternatives --config java
  231. You will now see a list of options for JREs to use. You need to choose the option that maps to the previous version of the JRE you were using (likely to be the OpenJDK).
  232.  
  233. 8.5) (Optional) Set up the previous Java Web Plugin
  234.  
  235. If you set up the new Sun Java Web Plugin you will need to complete this step to revert.
  236.  
  237. If you are using 32 bit Ubuntu type the following in the terminal:
  238.  
  239. Code:
  240. sudo rm /usr/lib/mozilla/plugins/libjavaplugin_oji.so
  241. If you are using 64 bit Ubuntu type the following in the terminal:
  242.  
  243. Code:
  244. sudo rm /usr/lib/mozilla/plugins/libnpjp2.so
  245. If you had to set up any of the settings in the about:config section (you should have noted the originals down) please change these back to the originals.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement