NOTE: Please see install instructions for macOS and Ubuntu in succeeding sections.
Sourcegraph has the following dependencies:
- Git (v2.18 or higher)
- Go (see current version in
.tool-versions) - Node JS (see current recommended version in .nvmrc)
- make
- Docker (v18 or higher)
- For macOS we recommend using Docker for Mac instead of
docker-machine
- For macOS we recommend using Docker for Mac instead of
- PostgreSQL (v12 or higher)
- Redis (v5.0.7 or higher)
- Yarn (v1.10.1 or higher)
- SQLite tools
- Golang Migrate (v4.7.0 or higher)
- Comby (v0.11.3 or higher)
- Watchman
You can choose to install Redis and/or PostgreSQL directly on your system, or you can run them as docker containers with docker compose. The following instructions will describe both options.
Running within a container provides some advantages such as storing the data separately from the container, you do not need to run it as a system service and its easy to use different database versions or multiple databases.
Running as system services might yield better performance, especially on macOS.
No matter which option you choose, docker is required because the development server starts additional docker containers.
The following are two recommendations for installing these dependencies:
-
Install Homebrew.
-
Install Docker for Mac.
optionally via
brewbrew install --cask docker -
Install Go, Yarn, Git, golang-migrate, Comby, SQLite tools, and jq with the following command:
brew install go yarn git gnu-sed golang-migrate comby sqlite pcre FiloSottile/musl-cross/musl-cross jq watchman -
(without docker) Install PostgreSQL and Redis
If you want to run Redis and/or PostgreSQL directly on your system install them with the follwing command:
brew install postgresql brew install redis -
(with docker) Install Docker Compose
We provide a docker compose file at
dev/redis-postgres.ymlto make it easy to run Redis and PostgreSQL as docker containers. Fortunatelydocker-composecomes with Docker for Mac so no additional step is required.See the official docker compose documentation.
-
Install the Node Version Manager (
nvm) using:NVM_VERSION="$(curl https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r .name)" curl -L https://raw.githubusercontent.com/nvm-sh/nvm/"$NVM_VERSION"/install.sh -o install-nvm.sh sh install-nvm.shAfter the install script is finished, re-source your shell profile (e.g.,
source ~/.zshrc) or restart your terminal session to pick up thenvmdefinitions. Re-running the install script will update the installation.NOTE:
nvmis implemented as a shell function, so it may not show up in the output ofwhich nvm. Usetype nvmto verify whether it is set up. There is also a Homebrew package fornvm, but it is unsupported by thenvmmaintainers.-
For fish shell users, you will want to install
basswhich you can get viaomf:curl -L https://get.oh-my.fish | fish omf install bass -
Then add the following to your
config.fish:function nvm bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv end set -x NVM_DIR ~/.nvm
-
-
Install the current recommended version of Node JS by running the following from the working directory of a sourcegraph repository clone:
nvm install nvm use --delete-prefixAfter doing this,
node -vshould show the same version mentioned in.nvmrcat the root of the sourcegraph repository.NOTE: Although there is a Homebrew package for Node, we advise using
nvminstead, to ensure you get a Node version compatible with the current state of the sourcegraph repository. -
(optional) Configure PostgreSQL and Redis to start automatically
If you have installed PostgreSQL and Redis directly on your system, start them with the following commands:
brew services start postgresql brew services start redisYou can stop them later by calling
stopinstead ofstartabove. -
Ensure
psql, the PostgreSQL command line client, is on your$PATH. Homebrew does not put it there by default. Homebrew gives you the command to run to insertpsqlin your path in the "Caveats" section ofbrew info postgresql. Alternatively, you can use the command below. It might need to be adjusted depending on your Homebrew prefix (/usr/localbelow) and shell (bash below).hash psql || { echo 'export PATH="/usr/local/opt/postgresql/bin:$PATH"' >> ~/.bash_profile } source ~/.bash_profile -
Open a new Terminal window to ensure
psqlis now on your$PATH.
-
Add package repositories:
# Go sudo add-apt-repository ppa:longsleep/golang-backports # Docker curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" # Yarn curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list -
Update repositories:
sudo apt-get update -
Install dependencies:
sudo apt install -y make git-all libpcre3-dev libsqlite3-dev pkg-config golang-go musl-tools docker-ce docker-ce-cli containerd.io yarn jq libnss3-tools # (without docker) install PostgreSQL and/or Redis if you don't want to run them as docker containers sudo apt install -y redis-server sudo apt install -y postgresql postgresql-contrib # install golang-migrate (you must rename the extracted binary to `golang-migrate` and move the binary into your $PATH) curl -L https://github.com/golang-migrate/migrate/releases/download/v4.7.0/migrate.linux-amd64.tar.gz | tar xvz # install comby (you must rename the extracted binary to `comby` and move the binary into your $PATH) curl -L https://github.com/comby-tools/comby/releases/download/0.11.3/comby-0.11.3-x86_64-linux.tar.gz | tar xvz # install watchman (you must put the binary and shared libraries on your $PATH and $LD_LIBRARY_PATH) curl -LO https://github.com/facebook/watchman/releases/download/v2020.07.13.00/watchman-v2020.07.13.00-linux.zip unzip watchman-*-linux.zip sudo mkdir -p /usr/local/{bin,lib} /usr/local/var/run/watchman sudo cp bin/* /usr/local/bin sudo cp lib/* /usr/local/lib sudo chmod 755 /usr/local/bin/watchman sudo chmod 2777 /usr/local/var/run/watchman # On Linux, you may need to run the following in addition: watchman watch <path to sourcegraph repository> # nvm (to manage Node.js) NVM_VERSION="$(curl https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r .name)" curl -L https://raw.githubusercontent.com/nvm-sh/nvm/"$NVM_VERSION"/install.sh -o install-nvm.sh sh install-nvm.sh # in repo dir: install current recommendend version of Node JS nvm install -
(with docker) Install Docker Compose
We provide a docker compose file at
dev/redis-postgres.ymlto make it easy to run Redis and PostgreSQL as docker containers.NOTE: Although Ubuntu provides a
docker-composepackage, we recommend to install the latest version viapipso that it is compatible with our compose file.See the official docker compose documentation for more details on different installation options.
-
(without docker) Configure startup services
If you have installed PostgreSQL and Redis directly on your system, start them with the following commands:
sudo systemctl enable --now postgresql sudo systemctl enable --now redis-server.service
asdf is a CLI tool that manages runtime versions for a number of different languages and tools. It can be likened to a language-agnostic version of nvm or pyenv.
We use asdf in buildkite to lock the versions of the tools that we use on a per-commit basis.
See the installation instructions on the official asdf documentation.
sourcegraph/sourcegraph uses the following plugins:
asdf plugin add golangasdf plugin add nodejs
# Import the Node.js release team's OpenPGP keys to main keyring
bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring
# Have asdf read .nvmrc for auto-switching between node version
## Add the following to $HOME/.asdfrc:
legacy_version_file = yesasdf plugin add yarnasdf uses versions specified in .tool-versions whenever a command is run from one of sourcegraph/sourcegraph's subdirectories.
You can install the all the versions specified in .tool-versions by running asdf install.