Note: This guide is assuming you are running a Debian or Debian based operating system. (Debian, Ubuntu, Linux Mint, Etc.) and may not be entirely up to date.

Step One: Set up your environment

Make sure your system is up to date:

$ sudo apt update
$ sudo apt upgrade

Install all build tools:

$ sudo apt install git-core ninja-build gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 lzop maven pngcrush schedtool lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev squashfs-tools openjdk-8-jre openjdk-8-jdk

Step Two: Configure Repo and Git

Make a directory for Repo, download it and add it to your path so it can be executed system wide:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

Make a folder to store the ROM’s source code (ownrom can be replaced with whatever you want):

$ mkdir ~/ownrom
$ cd ~/ownrom

Configure Git:

$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"

Step Three: Download the source

Get the source initialized:

$ repo init -u git://github.com/OwnROM/android -b own-n

Download the source (this can take a while depending on internet speed):

$ repo sync -jX --force-sync

replace X with the number of threads you want to use for syncing

Step Four: Build

Load build tools:

$ . build/envsetup.sh

Fix java heap error:

$ export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
$ ./prebuilts/sdk/tools/jack-admin kill-server
$ ./prebuilts/sdk/tools/jack-admin start-server

Build for your device (This can take time depending on the speed of your computer):

$ lunch
$ time mka ownrom

Between builds:

$ make clean