Tutorial: How to Install SamTools, HTSLib, and BCFTools on Ubuntu 18.04
gravatar for otwtgin2010
13 months ago by
otwtgin2010200 wrote:

Just thought I would contribute this since figuring it all out was a super confusing process consisting of a few hundred google searches. It's likely it was just me, but maybe there are a few other people like me who will benefit from being able to avoid the process. This was a clean Ubuntu 18.04 install. Probably most people do not have that luxury.

Install Updates and Required Packages

sudo apt-get update
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install libbz2-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libncurses5-dev 
sudo apt-get install libncursesw5-dev
sudo apt-get install liblzma-dev

Install HTSLIB

cd /usr/bin
wget https://github.com/samtools/htslib/releases/download/1.9/htslib-1.9.tar.bz2
tar -vxjf htslib-1.9.tar.bz2
cd htslib-1.9


cd ..
wget https://github.com/samtools/samtools/releases/download/1.9/samtools-1.9.tar.bz2
tar -vxjf samtools-1.9.tar.bz2
cd samtools-1.9

Install BCFTools

cd ..
wget https://github.com/samtools/bcftools/releases/download/1.9/bcftools-1.9.tar.bz2
tar -vxjf bcftools-1.9.tar.bz2
cd bcftools-1.9

Export To Path And Refresh

export PATH="$PATH:/usr/bin/bcftools-1.9"
export PATH="$PATH:/usr/bin/samtools-1.9"
export PATH="$PATH:/usr/bin/htslib-1.9"
source ~/.profile
ADD COMMENTlink written 13 months ago by otwtgin2010200

Thank you otwtgin2010 for the work. Others may benefit from it, if they want to compile these softwares from source. Another option would be to use the Anaconda package manager. With conda, things are as easy as conda install -c bioconda samtools, taking care of the dependencies internally.

ADD REPLYlink written 13 months ago by ATpoint21k

This is the best way to go about it, IMO. Neither apt-get nor brew allow creating environments.

ADD REPLYlink written 13 months ago by RamRS23k

+1 for sharing your experiences with other users. Keep on contributing!

As Ram said, in this case one should follow the instruction given by the authors of the program.

fin swimmer

ADD REPLYlink written 13 months ago by finswimmer12k

this was super helpful for my attempt to get HTSlib working

ADD REPLYlink written 5 months ago by MaxF10

That was an extremely helpful walk-through. I've been trying to install BCFtools following their guidelines, but failing miserably (the operation would stop due to not finding curl:curl.h directory). Now, it has worked just fine.

And sorry for the lay question - I am still taking slow steps in learning Unix - but what is the meaning of the last step, "export to path and refresh"? I tried looking on the export --help, but I am still quite not sure what it does.

Many thanks, @otwtgin2010 !

ADD REPLYlink written 26 days ago by dodausp110

It means that you have to put the folder where the executable is in into your .bashrc or .bash_profile like

export PATH=$PATH:/path/to/folder/with/executable

Still, it would be easier to use a package manager such as conda.

ADD REPLYlink modified 26 days ago • written 26 days ago by ATpoint21k
gravatar for RamRS
13 months ago by
Houston, TX
RamRS23k wrote:


Wait, you're using apt-get to install prerequisites but not the actual software you need? Why is that? Pretty sure samtools is available on apt-get.

source ~/.profile might override your $PATH settings if there is a statement in the profile file that overwrites (not appends to) the $PATH variable. You're better off with, say:

mkdir ~/myBinaries/
cd ~/myBinaries/
find /usr/bin/bcftools-1.9/ -type f -executable | xargs -I v_b ln -s v_b ./
find /usr/bin/samtools-1.9/ -type f -executable | xargs -I v_b ln -s v_b ./
find /usr/bin/htslib-1.9/ -type f -executable | xargs -I v_b ln -s v_b ./
cd -
echo 'export PATH=$PATH:~/myBinaries' >>~/.profile
source ~/.profile

Or, use a package manager and not worry about adding stuff to $PATH :-)

ADD COMMENTlink modified 13 months ago • written 13 months ago by RamRS23k

Got it - thank-you for the clarification! i tried apt-get but it was installing old versions. And the old versions were super buggy and didn't work with a lot of my sample files.

ADD REPLYlink written 13 months ago by otwtgin2010200

I see. Also, this information is available directly on the htslib site: http://www.htslib.org/download/

Plus the post contains less information than what's available on that site. Why create this post?

ADD REPLYlink written 13 months ago by RamRS23k

Thanks. Yeah, for someone who knows as much as they should, that would no doubt be plenty. But i guess for those who knows as little as i do :) - the things like how you download the file, how you extract it (or even that you need to extract it), that you need "make" installed are not self-evident.

ADD REPLYlink written 13 months ago by otwtgin2010200

You're right, but that's a rabbit hole. We have to stick to some pre-requisites that we can assume people that come here know. Command line basics is one of them. How to download a file (not necessarily using the command line), un-archive it (tar options, computer science stuff), cd into directories, know sudo stuff, etc. People who do not know that should be working with bioinformaticians who do and learning in the process, not searching online.

ADD REPLYlink modified 13 months ago • written 13 months ago by RamRS23k

Thanks and true! i guess i have a tendency to create my roof before my foundation, and the assumption that most others are the same way is an invalid one. And i don't mean this to be my personal beef about documentation that is not sufficient enough to make up for my lack of basic knowledge. Just hoping it will help someone else.

ADD REPLYlink written 13 months ago by otwtgin2010200
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 840 users visited in the last hour