Installing coala Natively

Note

If you have a working docker and you do not want to work with python,go to the bottom on the docker setup.

This page will run you through the installation of coala without docker. coalacurrently supports Linux, Windows and OS X.

Installing Python and Pip

In order to use coala, you need Python installed. In order to do so, you shouldinstall Python >= 3.4 from here.

The easiest way to install coala is using pip (Pip Installs Packages).If you don’t already have pip, you can install it like described in thepip installation guide.

Note

Pip is shipped with recent Python versions by default.

To check whether you have pip installed, type the following command which willalso show you more information about your current pip version:

  1. $ pip show pip

Make sure you have pip >= 8 installed as older versions might prevent coalafrom being installed properly.

Installing coala

There are three ways of installing coala. By using a virtualenv, by installingit system-wide or directly from source.

After successfully installing coala, you will need to install all thedependencies the bears have.

Note

If Java is installed after coala, you will need to restart your shell.

System Wide Installation

The simplest way to install coala is to do it system-wide, but this isgenerally discouraged in favor of using a virtualenv.

To install the latest most stable version of coala and supported bearssystem-wide, use:

  1. $ pip3 install coala-bears

Note

For this and all future steps, some steps require root access(also known as administrative privileges in Windows).

Unix based (OS X, Linux) - This can be achieved by using sudoin front of the command, as in: sudo command_name instead ofcommand_name

Windows - The easiest way on Windows is to start acommand prompt as an administrator and start setup.py.

To install the nightly build from our master branch, you can do:

  1. $ pip3 install coala-bears --pre

To install coala only (without any bears), you can do:

  1. $ pip3 install coala

Note

Ubuntu Users - Do not use apt-get install coalafor installing coala as that is different software.

Installing inside a pipenv

Pipenv is a user-friendly method of managing virtual environments andpackages.You can look at it as a mix of pip and virtualenv, so you don’t haveto manage them seperately for your projects.

We’ll now install pipenv by running the following command:

  1. $ pip3 install pipenv

Now we create a Python 3 environment for the project. Move to your projectdirectory and run the following command:

  1. $ pipenv --three

The above command will create a virtual environment isolated from your systemglobal installation.

To install coala and all bears, run the following command:

  1. $ pipenv install coala-bears

Great, you have now setup a pipenv environment for your project directory andinstalled coala using it.You can now activate the pipenv by running:

  1. $ pipenv shell

Your virtual environment (virtualenv) is now active. You’ll notice the changebefore the $ sign on the command-line which will have your projectdirectory name and some alpha-numeric value to make it unique.You can use coala by running the coala command and exit the virtualenvenvironment by entering exit at any time.

You can read more about pipenv in itsdocumentation.

Installing inside a virtualenv

Although pipenv sorts all your package and virtual environment needs, ifyou still feel the need to use virtualenv separately you can follow thesteps given below.

You can read more aboutit at the virtualenv documentation.

First, we need to install virtualenv to the system. You may already have thisinstalled as virtualenv or pyvenv. If you do not, this can be donewith pip3 easily:

  1. $ pip3 install virtualenv

Once you have virtualenv installed, just fire up a shell and createyour own environment. I usually create a project folder and a venvfolder:

  1. $ virtualenv venv

Note

If you have both Python 3 and Python 2 installed, usevirtualenv venv -p $(which python3).This creates an isolated Python 3 environment named venvin your current directory, as coala only works for Python 3.4 and above.

Now, whenever you want to work on the project, you only have to activatethe corresponding environment.

On Unix based systems (OS X and Linux), this can be done with:

  1. $ source venv/bin/activate

And on Windows this is done with:

  1. $ venv\scripts\activate

Finally, you should install coala and the supported bears inside the activatedvirtualenv with:

  1. (venv)$ pip3 install coala-bears

Using coala With Docker

Use this installation method if you just simply want to use coala.

The recommended way to use coala is using docker: coala has a lot ofdependencies because it has so much code analysis for so many languages. If youuse our docker image, you can run it like any other tool but you do not need tocare about those! The general command to run coala is:

  1. $ docker run -ti -v $(pwd):/app --workdir=/app coala/base coala --version

Note

This will automatically download the docker image with all the coaladependencies for you. The image may take up a bit over 2GB of space on yourdisk. Check out the native installation if this is not for you.

Windows

If you use Windows, you can install docker easily usingDocker Toolbox.

Bleeding edge installation

If you would like to develop coala, you should check out ourNewcomer Tutorial andget in touch with us.

  1. $ pip3 install coala-bears --pre

Also check out the Developers Setup docs.

Alternate location installation

If you want to install coala to an alternate location, you can e.g. callpython3 setup.py install —prefix=/your/prefix/location. Other installationoptions are documented in thePython docs.

Note

If you are using a proxy, follow these steps:

  • Set up your system-wide proxy.
  • Use sudo -E pip3 install coala (the -E flag takes theexisting environment variables into the sudo environment).You could also set your pip.conf file to use a proxy. To find out more,read Using pip behind a proxy on StackOverflowfor further clarification.

Optional Dependencies

Those dependencies are not mandatory. You may install all of thedependencies if you want to install all the bears. The bearapplication also asks for the packages needed in case it does nothave it.

The requirements files ( Gemfile, requirements.txt, etc.) are inthe coala-bears repository and you should not get them fromsource, but you should git clone the repository if you want toexecute those commands.

This section lists dependencies of coala that are not automaticallyinstalled. On Windows, you can get many with nuget(https://www.nuget.org/). On Mac, Homebrew will help you installingdependencies (http://brew.sh/). These dependencies require you to havethe repositorycloned locally.

JS Dependencies

coala features a lot of bears that use linters written in JavaScript. Inorder for them to be usable, you need to install them via npm(http://nodejs.org/), while in the project directory:

  1. $ npm install -g

If a bear still doesn’t work for you, please make sure that you have arecent version of npm installed. Many linux distributions ship avery old one.

Ruby Dependencies

There are also a few bears which rely on Ruby Gems. In order to install them,you will need Gem (https://rubygems.org/pages/download/) installedand bundler.

To grab bundler, use:

  1. $ gem install bundler

Then, simply run:

  1. $ bundle install
  2. $ git add Gemfile Gemfile.lock

Binary Dependencies

Some bears need some binary dependencies. Some of those include:

  • PHPLintBear: Install php
  • GNUIndentBear: Install indent (be sure to use GNU Indent, Mac shipsa non-GNU version that lacks some functionality.)
  • CSharpLintBear: Install mono-mcsFor further help with installing bears with binary dependencies, don’t hesitatetoget in touch with us.

Clang

coala features some bears that make use of Clang. In order for them towork, you need to install libclang:

  • Ubuntu: apt-get install libclang1
  • Fedora: dnf install clang-libs (Use yum instead of dnf onFedora 21 or lower.)
  • ArchLinux: pacman -Sy clang
  • Windows: nuget install ClangSharp
  • OS X: brew install llvm —with-clangIf these do not help you, search for a package that containslibclang.so.

On Windows, you need to execute this command to add the libclang path tothe PATH variable permanently (you need to be an administrator):

setx PATH "%PATH%;%cd%\ClangSharp.XXX\content\x86" \M

For x86 python or for x64 python:

setx PATH "%PATH%;%cd%\ClangSharp.XXX\content\x64" \M

Replace “XXX” with the ClangSharp version you received from nuget.

Shell-Autocompletion Support

If you are a bash/zsh user , checkout theguideto set up autocompletion for coala arguments and bear names.

Installation Errors

In case you are gettingValueError:('Expected version spec in', 'appdirs ~=1.4.0', 'at',' ~=1.4.0'), then don’t panic. It happens when you are using an outdatedversion of pip that doesn’t support our version specifiers yet.

Ideally, you have to create a virtual environment with a newer pip:

  1. $ pip3 install virtualenv$ virtualenv -p python3 ~/venv/coala$ . ~/venv/coala/bin/activate$ pip install -U pip$ pip install coala-bears

You have to activate this virtualenv on every terminal session you want to usecoala though (tip: add it to bashrc!).

Generating Documentation

coala documentation isin a separate repository.First you need to install the requirements:

  1. $ pip3 install -r requirements.txt

To generate the documentation coala uses sphinx. Documentation can begenerated by running the following command while in root directory of therepository:

  1. $ make html

You can then open _build\html\index.html in your favouritebrowser.

See Writing Documentationfor more information.