Installing Oracle JDK 7 on Ubuntu 12.04

- Download Java SE 7u4 from Oracle and Uncompress it
$ tar xf jdk-7u4-linux-x64.tar.gz

– JDK 7 package is extracted into jdk1.7.0_04 directory. Move this directory to /usr/lib/jvm/
$ sudo mv ./jdk1.7.0_04 /usr/lib/jvm/jdk1.7.0_04-sun

– Now run
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_04-sun/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_04-sun/bin/javac" 1
$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_04-sun/bin/javaws" 1

– Set newly installed java as default
$ sudo update-alternatives --config java

– Verify version of new JDK 7 installation
$ java -version

– Repeate above steps for
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config javaws

UPDATE : Please read the update-alternatives(8) man page for information

Shamelessly copied from –

MongoDB on EBS with RAID10, LVM, XFS

I keep forgetting these commands since those are used once in a blue moon, so
writing this post to refer them when needed.

As mentioned in MongoDB – Amazon EC2 Docs [1], we will create a RAID10 array.
RAID10 provides both striping (speed) and mirroring (redundancy).[2]

– Create RAID10 array

4 Disks of 8 GB Each – 16 Gigs available for use

$ mdadm --verbose --create /dev/md0 --level=10 --chunk=256 --raid-devices=4 /dev/sdf{1..4}
$ blockdev --setra 512 /dev/md0 # [3]

I used to set “readahead” to “65536” [4] , but then I got following warning with MongoDB 2.4.x

Readahead for /path/to/mongo/partition is set to 2048KB, we suggest setting it to 256KB.

Refer [3] for more details.

$ mdadm --detail --scan >> /etc/mdadm/mdadm.conf

16 Gigs is not a huge space, You will have to increase this space as your DB grows. For that we need LVM [5] .

– Create a physical volume
$ pvcreate /dev/md0

– Create a volume group
$ vgcreate VOL_GRP_NAME /dev/md0

– Check available Free Physical Extents (Free PE), use that number in next command
$ vgdisplay VOL_GRP_NAME

$ lvcreate --name LOGICAL_VOL_NAME --extents +100%FREE VOL_GRP_NAME

– Create file system
$ mkfs.xfs -f /dev/VOL_GRP_NAME/LOGICAL_VOL_NAME

– Mount newly created partition
$ mount -t xfs -o noatime,noexec,nodiratime /dev/VOL_GRP_NAME/LOGICAL_VOL_NAME /MOUNT_POINT/

– Put an /etc/fstab entry so the partition will mount automatically if you reboot.
$ echo "/dev/VOL_GRP_NAME/LOGICAL_VOL_GRP /MOUNT_POINT xfs noatime,noexec,nodiratime 0 0" >> /etc/fstab

– When you want to increase the size of an array, create another RAID10 array /dev/md1

– Extend Volume Group
$ vgextend VOL_GRP_NAME /dev/md1

– Extend Logical Volume
$ lvextend -l +100%FREE /dev/VOL_GRP_NAME/LOGICAL_VOL_NAME

– Finally extend file system on it
$ xfs_growfs /MOUNT_POINT

(You don’t have to un-mount partition or reboot system since XFS supports live expansion) [6]




Generally when you try opening any X application, say xclock or xterm, as a root user on a remote system, It gives an error saying “Can’t open display”. To get rid of this message what you can do is,

– First ssh with -X into remote system
$ ssh -vX

– Export a variable
$ export XAUTHORITY="~/foo/.Xauthority"

– Start X app (I am assuming user “foo” has a superuser privileges on remote system)
$ sudo xterm

Setting up Emacs for Clojure using Lein

  • Create a directory “~/bin”
  • $ cd ~/bin

  • Download “lein”
  • $ wget

  • Install packages
  • $ aptitude -Ry install emacs23-nox openjdk-6-jdk

  • Create a project directory
  • $ lein new myproject

  • Edit project.clj
  • $ cd myproject
    $ emacs project.clj

    Add “swank-clojure” and “clojure-contrib” lines to it

    File should look like this

    (defproject myproject "1.0.0-SNAPSHOT"
    :description "FIXME: write description"
    :dependencies [[org.clojure/clojure "1.2.1"]
    [org.clojure/clojure-contrib "1.2.0"]]
    :dev-dependencies [[swank-clojure "1.2.1"]])

    Save file and exit out of emacs

  • Download “lein” dependencies
  • $ lein deps

  • Install “emacs” packages
  • Open following link in browser

    Open “emacs” and Switch to *scratch* buffer

    $ emacs -nw and then C-x C-b *scratch*

    Follow instructions given on “install.html” link, alternatively copy following
    code to *scratch* buffer

    (let ((buffer (url-retrieve-synchronously
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer))))

    Evaluate above code using “M-x eval-buffer” command

  • Install “emacs modes”
  • Run “M-x package-list-packages”

    Install “swank-clojure” package
    Use “C-s” to Search package name
    Use “i” to select package and then press “x” to install.
    This should also install “clojure-mode” “slime” “slime-repl” packages.

  • Run “swank server”
  • Switch to another terminal
    $ cd ~/myproject
    $ lein swank

    This will start “swank” server on by default

  • Connect to “swank” using “slime”
  • Go back to running emacs instance and type

    “M-x slime-connect”

    It will prompt for “host” and “port”, press to accept default values

    Your Hacking Starts Now!!!

    You may get a version mismatch warning after running “slime-connect”. To remove
    this warning

    $ cd ~/.emacs.d/elpa/slime-20100404/
    and remove .elc file
    $ rm slime.elc

    Distro : Ubuntu 11.04
    Package Versions : Emacs – 23.2, Lein – 1.6.1, Clojure – 1.2.1, Clojure-Contrib – 1.2.0, Swank-Clojure – 1.2.1, OpenJDK-6-JDK – 6b22-1

    Changing Caps_Lock as third Ctrl key

  • create map
  • $ sudo dumpkeys | head -1 > /usr/share/keymaps/

  • add following lines to that file
  • keycode 58 = Control # This makes Caps act as Ctrl
    # keycode 29 = Caps_Lock # This makes Ctrl act as Caps
    # alt_is_meta # This fixes the Alt key

  • run loadkeys on that file
  • $ sudo loadkeys /usr/share/keymaps/

  • to revert and load default keymap
  • $ sudo loadkeys -d

    Reference :

    Another option is to execute following command

    $ setxkbmap -option ctrl:nocaps