Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.

Friday, May 10, 2013

Install Samtools on UNIX System

Samtools is a very useful tool for manipulating and visualizing .bam files.  Here is a quick guide on how to install Samtools.  First download the most current version from the Samtools website.  Unzip the file using either tar xvjf or the extract command.  Go into the newly created directory and compile the code by typing "make".  Your code should look something like this.

The next step is then to modify your .bashrc file so that when you type "samtools" it calls the program.  To do this open your .bashrc file and add the following line of code, where directory is equal to the directory that you have installed Samtools in.

Make sure as a final step to source the .bashrc file by entering source .bashrc into the command line.


  1. Hi.

    I've successfully downloaded the current Samtools version. I tried to extract it using the command you gave above but it didn't work. This is what appeared.

    $ tar xvjf samtools-0.1.19.tar.bz2
    tar (child): samtools-0.1.19.tar.bz2: Cannot open: No such file or directory
    tar (child): Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Error is not recoverable: exiting now

    I'm a beginner in this field so I would appreciate if you could give me a more detailed instruction for installing SAMTOOLS.


    1. Hi Mark,
      It looks like you are not in the same directory as the samtools-0.1.19.tar.bz2 file that you downloaded. Make sure you cd to the same directory and can see the samtools-0.1.19.tar.bz2 file in your current directory (the ls command is useful for that). Then run the tar xvjf samtools-0.1.19.tar.bz2 command. Hope this helps!

    2. Hi.

      Actually I'm using cygwin to install samtools on my pc (windows7). I encountered some problem following your steps and i figured out that maybe it's because I'm using cygwin. Nonetheless, I was able to extract it and change directory by getting some ideas from your answers. Now, my problem is this: When I proceed to make these appear

      $ make
      make[1]: Entering directory `/home/ahnslab/samtools-0.1.19'
      make[2]: Entering directory `/home/ahnslab/samtools-0.1.19'
      make[2]: Nothing to be done for `lib'.
      make[2]: Leaving directory `/home/ahnslab/samtools-0.1.19'
      make[2]: Entering directory `/home/ahnslab/samtools-0.1.19/bcftools'
      make[2]: Nothing to be done for `lib'.
      make[2]: Leaving directory `/home/ahnslab/samtools-0.1.19/bcftools'
      make[2]: Entering directory `/home/ahnslab/samtools-0.1.19/misc'
      make[2]: Nothing to be done for `lib'.
      make[2]: Leaving directory `/home/ahnslab/samtools-0.1.19/misc'
      gcc -c -g -Wall -O2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_USE_KNETFILE -D_CURSES_LIB=1 -I. bam_tview_curses.c -o bam_tview_curses.o
      bam_tview_curses.c:5:20: fatal error: curses.h: No such file or directory
      compilation terminated.
      Makefile:24: recipe for target `bam_tview_curses.o' failed
      make[1]: *** [bam_tview_curses.o] Error 1
      make[1]: Leaving directory `/home/ahnslab/samtools-0.1.19'
      Makefile:27: recipe for target `all-recur' failed
      make: *** [all-recur] Error 1

      I don't know now how to proceed. Hope you could still help me.

      Thank you.

    3. Mike,
      You have reached the limits of my knowledge on installing samtools. I am not familiar with installing on Windows via cygwin. My guess is that Winodws does not have the correct compiler to make the samtools package, but I could be wrong. Best wishes getting this up and running. When you get it figured out, please leave a comment detailing how you got it working.

    4. I had the some problem today trying to install samtools 0.1.19 on a ubuntu machine. It turns out that the ncurses library is not installed by default.

      On Debian/Ubuntu, install the packages libncurses5-dev and libncursesw5-dev:

      sudo apt-get install libncurses5-dev libncursesw5-dev

      On Fedora/RedHat/CentOS, install the packages ncurses-devel and ncurses:

      sudo yum install ncurses-devel ncurses

      make clean

      Worked for me. Hope that helps.

    5. Thanks for the input, sunnyjoy!

    6. some internet tidying... on ubuntu you can just install from the repositories now (currently v0.1.19):

      sudo apt-get install samtools

  2. Hi Admin! I hope you are still manning this old post? Ive just installed Samtools on my Mac OsX and I'm struggling to see what I'm doing wrong. So I cd to samtools, then "ls" to make sure I'm good and when I put in make it a whole load of stuff comes up and ends in nothing can be done for "lib". make[1]: *** [bam_color.o] Error 1
    make: *** [all-recur] Error 1

    It allows me to enter export PATH=$PATH:/directory/samtools-0.1.19
    but when I source.bashrc it says command not found.

    Whats happening? Im very new to bioinformatics. Any suggestions greatly appreciated :)

    1. Hi Meri, not exactly sure what is going wrong. I know this works with UNIX, just not sure why its not going smoothly for your Mac. I would maybe try installing an older version. Let me know if you figure things out. Best wishes and thanks for stopping by.

  3. Hi Admin,

    I've successfully installed the SamTools and compiled it per the "make" command, but I can't seem to find my .bashrc file. Is this something that should already be in my home directory, or do I have to make one if its not there. Also, should i make it in the same sub-directory that SamTools is present in, or is it okay if I make it in a more general parent directory.

    Thanks for your help!