Dec 24 2011

VirtualBox with Gentoo(3)

Category: English posts,TechnicalIuliana @ 3:35

Well, we have a VM with Gentoo and an interface. Let’s make the virtual machine more flexible and more cooperative with the operating system on your computer. For this we have to install VirtualBox drivers on your Gentoo. After restarting your system upon setting up the interface you can log on to your desktop interface. But for installing other tools you will still  need the console. For the purpose of this tutorial we will use the Kde terminal named konsole.

To open a terminal: click the button on the left corner of the screen (the “K” button) and in the menu that is displayed at the top there is a text field. Type konsole and click on one of the results returned. (print-screen) Or press Alt +F2 and the same text field will appear at the top of your desktop. You can use it to start any application you want. You will be logged in with the normal user so in order to install things you need root access. So, in the terminal you need to use the su command:

# su -

You will be asked for the root password which you will type and then you can start installing. (By the way if any emerge process happens to fail, you can force to continue by using: # emerge –resume)

The steps to tune up your virtual machine to work with your operating system are as follows: (You will be working now in a konsole terminal)

# emerge -s virtualbox
# emerge -p app-emulation/virtualbox-guest-additions
# emerge app-emulation/virtualbox-guest-additions
# nano -w /etc/conf.d/modules
Add line modules="vboxvideo" and save(Ctrl+X,Y)
# usermod -aG vboxguest jules

Now you can use Right Ctrl +F to switch to/from full screen with your virtual machine and also the copy+paste between the supporting operating system and the Gentoo in the VirtualBox VM.

Now let’s make it an usable Java development machine. First we will need a few tools to make your life easier:
Step1. Firefox – you wil need a browser, because you might want to download some tools from the Internet using wget and you might want to be able to copy&paste the link instead of always writing it by hand. If you are not a Firefox fan you can use the default KDE browser: Konqueror, but I will give you instructions on how to install Firefox and if you  want another browser like Opera on Chrome you can just execute the same commands and replace Firefox with the name of the browser you want.

There are two types of packages you can install. Packages which end in -bin are easier to install because they contain the dependencies needed and have no need to be compiled on your system so their installation will take less time.  Packages that don’t end in -bin are packages that need to be compiled on your system. Their main advantage is that being compiled on your system they will be optimized to run on it and also bugs in precompiled packages will not be present. Sometimes precompiled packages will not be available for installation because of severe bugs, so then  you will have no choice but to use these ones.  Their main disadvantages are:

  • you might need to edit make.conf to add flags for dependencies they need to install
  • compilation time might be quite long
  • when a new version appears you need to remove the old version and install the new one, you can’t make a simple click update

So to install Firefox you have to see what versions are available for install. (we’ll talk about masked packages when we will need to install one, no need to get into this now) And this is how you do it:
First

# emerge -s firefox

In your console you will see something like this:

vm-gentoo-jules1 # emerge -s firefox
Searching...
[ Results for search key : firefox ]
[ Applications found : 2 ]

 * www-client/firefox
Latest version available: 8.0
Latest version installed: 8.0
Size of files: 88,446 kB
Homepage: http://www.mozilla.com/firefox
Description: Firefox Web Browser
License: || ( MPL-1.1 GPL-2 LGPL-2.1 )

* www-client/firefox-bin
Latest version available: 8.0
Latest version installed: [ Not Installed ]
Size of files: 53,052 kB
Homepage: http://www.mozilla.com/firefox
Description: Firefox Web Browser
License: || ( MPL-1.1 GPL-2 LGPL-2.1 )

At this moment the precompiled package for Firefox has some bugs and is not available, you can try to install it:

# emerge www-client/firefox-bin

But it will fail. So I installed the raw version that needed compiling and it took a while.

# emerge www-client/firefox

Step2. Midnight Commander: For used to Total Commander this a the Linux in console alternative. I tried to install it as I installed Firefox, but because of some dependency issues I had to use a different approach, which I will also present to you here. This approach consists in downloading the sources, compiling them and installing MC manually. Here are the steps:

# wget http://www.ibiblio.org/pub/Linux/utils/file/managers/mc/mc-4.6.1.tar.gz
# tar zvfx mc-4.6.1.tar.gz
# cd mc-4.6.1
# ./configure -silent
# make
# make install

Test it! First close the terminal and open a new one and then:

# env-update
# mc

Step3. Java: Because in our initial make.conf we added the java and java6 flags you system will come with a working JVM. But we want the latest version which currently is 7. Surprisingly the JAVA_HOME environment variable is set too. (Nice, less work for us :D). This variable is used by applications like Ant, Tomcat, Eclipse, Oracle for execution of their own stuff.
As a Linux user the best practice is to set the value of JAVA_HOME to point to a symlink which points to the directory where jdk has been unpacked, this way when you install a new version you can just modify the symlink to point to the new directory, and no log off to reload JAVA_HOME is needed.

So let’s do this:

# java -version
# echo $JAVA_HOME

Result:

 /etc/java-config-2/current-system-vm 
# cd /etc/java-config-2/
# ls -la

Result:

total 16 drwxr-xr-x 3 root root 4096 Dec 16 19:46 . drwxr-xr-x 57 root root 4096 Dec 21 12:32 .. drwxr-xr-x 2 root root 4096 Dec 16 19:43 build lrwxrwxrwx 1 root root 25 Dec 16 19:46 current-system-vm -> /usr/lib/jvm/icedtea6-bin -rw-r--r-- 1 root root 61 Jan 14 2009 virtuals 

The current-system-vm is either the symlink pointing to the directory where java is installed or the symlink to a symlink that points to the directory where java is installed. So all we have to do to change the version of java installed is to make that symlink point to the new directory.

# cd /usr/lib/jvm
# ls -la

Result:

total 76 drwxr-xr-x 2 root root 4096 Dec 16 19:46 . drwxr-xr-x 76 root root 69632 Dec 20 16:33 .. lrwxrwxrwx 1 root root 24 Dec 16 19:46 icedtea6-bin -> /opt/icedtea6-bin-1.10.4 

And if we go to the last location we will see the typical structure of a Jdk. ( Directories: bin, include, jre, lib, man). We are now ready to go to java.sun.com (which now redirects you to oracle.com) and downloading the latest version of the jdk that corresponds to your operating system. To find the latest version browse the Download menu and click on Java for Developers link. Eventually you should get to a page that looks like this. You can click any of the download buttons next to the rounded option, but I will download JDK 7 even if it is considered unstable by the Java Developers Community. On the next page select your operating system and your processor type (we will download the Linux X86 version jdk-7u2-linux-i586.tar.gz), check the “Accept License Agreement” radio box, then click on the corresponding link.

If you downloaded the jdk archive with firefox it should be in /home/[user_name]/ directory. Extract it:

# tar xfp jdk-7u2-linux-i586.tar.gz 
Open MC (installed at Step2.)
# mc

And on left navigate to where the current installed java directory is and on the right navigate to where
your unpacked new jdk is. (Sample) Click on the right side on the directory and press F5 to copy it on the left side.
Now all we have to do is to go back to /usr/lib/jvm and create a symlink for our java version. We will not edit the  icedtea6-bin symlink, because that symlink corresponds to a Java6 version, and we want to be able to connect the dots later, just in case. Plus it is more logical this way, right?

# cd /usr/lib/jvm
# ln -s /opt/jdk1.7.0_02/ /usr/lib/jvm/java7-bin
# cd/etc/java-config-2/
# rm current-system-vm
# ln -s /usr/lib/jvm/java7-bin current-system-vm

Result:

vm-gentoo-jules1 # java -version
java version "1.7.0_02" Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode)

Step4. Eclipse: to write java code you need an editor and I will always recommend this one, because it’s small, it is fast and intuitive. Current location on Eclipse.Org where we can find versions of Eclipse which support Java 7 development is this. We will need the version for Linux x86. Download it and unpack-it where you want to. After that, just open a file manager, Kde has one named Dolphin, go to the Eclipse directory and click on the file that has an icon that looks like a gear. That is the executable file that will start the editor.

This is all for now, next time we will set up Ant, Maven, Oracle and Tomcat. As always, I welcome your input as I want to improve these series of posts to be more precise and useful for any starting developer.

Tags: , , , , ,

Leave a Reply