2018-07-23 22:29:31 -04:00
**DO NOT READ THIS FILE ON GITHUB, GUIDES ARE PUBLISHED ON https://guides.rubyonrails.org.**
2014-12-23 17:32:50 -05:00
2012-10-17 09:15:55 -04:00
Development Dependencies Install
================================
2019-08-09 17:30:15 -04:00
This guide covers how to set up an environment for Ruby on Rails core development.
2012-10-17 09:15:55 -04:00
2012-11-29 17:25:02 -05:00
After reading this guide, you will know:
2013-05-01 22:14:33 -04:00
* How to set up your machine for Rails development
2012-10-17 09:15:55 -04:00
--------------------------------------------------------------------------------
The Easy Way
------------
The easiest and recommended way to get a development environment ready to hack is to use the [Rails development box ](https://github.com/rails/rails-dev-box ).
The Hard Way
------------
2017-08-18 11:39:25 -04:00
In case you can't use the Rails development box, see the steps below to manually
build a development box for Ruby on Rails core development.
2012-10-17 09:15:55 -04:00
### Install Git
2017-08-18 12:55:46 -04:00
Ruby on Rails uses Git for source code control. The [Git homepage ](https://git-scm.com/ ) has installation instructions. There are a variety of resources on the net that will help you get familiar with Git:
2012-10-17 09:15:55 -04:00
2017-08-18 12:55:46 -04:00
* [Try Git course ](https://try.github.io/ ) is an interactive course that will teach you the basics.
* The [official Documentation ](https://git-scm.com/documentation ) is pretty comprehensive and also contains some videos with the basics of Git.
2017-08-18 19:23:37 -04:00
* [Everyday Git ](https://schacon.github.io/git/everyday.html ) will teach you just enough about Git to get by.
2017-08-18 12:55:46 -04:00
* [GitHub ](https://help.github.com/ ) offers links to a variety of Git resources.
* [Pro Git ](https://git-scm.com/book ) is an entire book about Git with a Creative Commons license.
2012-10-17 09:15:55 -04:00
### Clone the Ruby on Rails Repository
Navigate to the folder where you want the Ruby on Rails source code (it will create its own `rails` subdirectory) and run:
```bash
2017-08-18 12:55:46 -04:00
$ git clone https://github.com/rails/rails.git
2012-10-17 09:15:55 -04:00
$ cd rails
```
2018-05-13 15:37:44 -04:00
### Install Additional Tools and Services
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
Some Rails tests depend on additional tools that you need to install before running those specific tests.
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
Here's the list of each gems' additional dependencies:
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
* Action Cable depends on Redis
* Active Record depends on SQLite3, MySQL and PostgreSQL
* Active Storage depends on Yarn (additionally Yarn depends on
[Node.js ](https://nodejs.org/ )), ImageMagick, FFmpeg, muPDF, and on macOS
also XQuartz and Poppler.
* Active Support depends on memcached and Redis
* Railties depend on a JavaScript runtime environment, such as having
[Node.js ](https://nodejs.org/ ) installed.
2013-07-29 09:46:09 -04:00
2018-05-13 15:37:44 -04:00
Install all the services you need to properly test the full gem you'll be
making changes to.
2013-07-29 09:46:09 -04:00
2018-05-13 15:37:44 -04:00
NOTE: Redis' documentation discourage installations with package managers as those are usually outdated. Installing from source and bringing the server up is straight forward and well documented on [Redis' documentation ](https://redis.io/download#installation ).
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
NOTE: Active Record tests _must_ pass for at least MySQL, PostgreSQL, and SQLite3. Subtle differences between the various adapters have been behind the rejection of many patches that looked OK when tested only against single adapter.
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
Below you can find instructions on how to install all of the additional
tools for different OSes.
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
#### macOS
2013-08-16 07:04:28 -04:00
2018-05-13 15:37:44 -04:00
On macOS you can use [Homebrew ](https://brew.sh/ ) to install all of the
additional tools.
2013-08-16 07:04:28 -04:00
2018-05-13 15:37:44 -04:00
To install all run:
2013-08-16 07:04:28 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ brew bundle
2013-08-16 07:04:28 -04:00
```
2018-05-13 15:37:44 -04:00
You'll also need to start each of the installed services. To list all
available services run:
2013-08-16 07:04:28 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ brew services list
2013-08-16 07:04:28 -04:00
```
2018-05-13 15:37:44 -04:00
You can then start each of the services one by one like this:
2013-08-16 07:04:28 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ brew services start mysql
2013-08-16 07:04:28 -04:00
```
2018-05-13 15:37:44 -04:00
Replace `mysql` with the name of the service you want to start.
2014-08-24 13:29:11 -04:00
2018-05-13 15:37:44 -04:00
#### Ubuntu
2014-08-24 13:29:11 -04:00
2018-05-13 15:37:44 -04:00
To install all run:
2012-10-17 09:15:55 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ sudo apt-get update
2019-09-22 18:20:56 -04:00
$ sudo apt-get install sqlite3 libsqlite3-dev mysql-server libmysqlclient-dev postgresql postgresql-client postgresql-contrib libpq-dev redis-server memcached imagemagick ffmpeg mupdf mupdf-tools libxml2-dev
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
# Install 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
$ sudo apt-get install yarn
2012-10-17 09:15:55 -04:00
```
2018-05-13 15:37:44 -04:00
#### Fedora or CentOS
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
To install all run:
2012-10-17 09:15:55 -04:00
```bash
2019-09-22 18:20:56 -04:00
$ sudo dnf install sqlite-devel sqlite-libs mysql-server mysql-devel postgresql-server postgresql-devel redis memcached imagemagick ffmpeg mupdf libxml2-devel
2013-08-21 19:00:47 -04:00
2018-05-13 15:37:44 -04:00
# Install Yarn
# Use this command if you do not have Node.js installed
$ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
# If you have Node.js installed, use this command instead
$ curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
$ sudo dnf install yarn
2013-08-21 19:00:47 -04:00
```
2018-05-13 15:37:44 -04:00
#### Arch Linux
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
To install all run:
2012-10-17 09:15:55 -04:00
```bash
2019-09-22 18:20:56 -04:00
$ sudo pacman -S sqlite mariadb libmariadbclient mariadb-clients postgresql postgresql-libs redis memcached imagemagick ffmpeg mupdf mupdf-tools poppler yarn libxml2
2020-01-03 20:15:43 -05:00
$ sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
$ sudo systemctl start redis mariadb memcached
2012-10-17 09:15:55 -04:00
```
2018-05-13 15:37:44 -04:00
NOTE: If you are running Arch Linux, MySQL isn't supported anymore so you will need to
use MariaDB instead (see [this announcement ](https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/ )).
2013-07-24 12:12:00 -04:00
2018-05-13 15:37:44 -04:00
#### FreeBSD
2013-07-24 12:12:00 -04:00
2018-05-13 15:37:44 -04:00
To install all run:
2013-07-29 09:46:09 -04:00
```bash
2019-09-22 18:20:56 -04:00
$ pkg install sqlite3 mysql80-client mysql80-server postgresql11-client postgresql11-server memcached imagemagick ffmpeg mupdf yarn libxml2
2018-05-13 15:37:44 -04:00
# portmaster databases/redis
2014-04-06 14:57:20 -04:00
```
2018-11-20 10:36:47 -05:00
Or install everything through ports (these packages are located under the
2018-05-13 15:37:44 -04:00
`databases` folder).
2013-07-29 09:46:09 -04:00
2018-05-13 15:37:44 -04:00
NOTE: If you run into troubles during the installation of MySQL, please see
2019-10-03 20:22:29 -04:00
[the MySQL documentation ](https://dev.mysql.com/doc/refman/en/freebsd-installation.html ).
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
### Database Configuration
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
There are couple of additional steps required to configure database engines
required for running Active Record tests.
2012-10-17 09:15:55 -04:00
In order to be able to run the test suite against MySQL you need to create a user named `rails` with privileges on the test databases:
2020-07-21 19:49:49 -04:00
```sql
2012-12-09 11:24:33 -05:00
$ mysql -uroot -p
mysql> CREATE USER 'rails'@'localhost';
2012-10-17 09:15:55 -04:00
mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.*
to 'rails'@'localhost';
mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.*
to 'rails'@'localhost';
2013-12-31 10:04:56 -05:00
mysql> GRANT ALL PRIVILEGES ON inexistent_activerecord_unittest.*
to 'rails'@'localhost';
2012-10-17 09:15:55 -04:00
```
2019-08-09 17:30:15 -04:00
PostgreSQL's authentication works differently. To set up the development environment
2014-08-24 13:29:11 -04:00
with your development account, on Linux or BSD, you just have to run:
2012-10-17 09:15:55 -04:00
```bash
$ sudo -u postgres createuser --superuser $USER
```
2014-08-24 13:29:11 -04:00
2017-08-18 11:39:25 -04:00
and for macOS:
2014-08-24 13:29:11 -04:00
2014-04-06 14:57:20 -04:00
```bash
$ createuser --superuser $USER
```
2012-10-17 09:15:55 -04:00
2018-05-13 15:37:44 -04:00
Then, you need to create the test databases for both MySQL and PostgreSQL with:
2012-10-17 09:15:55 -04:00
```bash
$ cd activerecord
2018-05-13 15:37:44 -04:00
$ bundle exec rake db:create
2012-10-17 09:15:55 -04:00
```
2018-05-13 15:37:44 -04:00
NOTE: You'll see the following warning (or localized warning) during activating HStore extension in PostgreSQL 9.1.x or earlier: "WARNING: => is deprecated as an operator".
You can also create test databases for each database engine separately:
2013-01-23 10:15:31 -05:00
```bash
$ cd activerecord
2018-05-13 15:37:44 -04:00
$ bundle exec rake db:mysql:build
$ bundle exec rake db:postgresql:build
2013-01-23 10:15:31 -05:00
```
2018-05-13 15:37:44 -04:00
and you can drop the databases using:
2013-01-23 10:15:31 -05:00
```bash
$ cd activerecord
$ bundle exec rake db:drop
```
2017-08-18 11:39:25 -04:00
NOTE: Using the Rake task to create the test databases ensures they have the correct character set and collation.
2012-10-17 09:15:55 -04:00
2013-08-23 11:59:11 -04:00
If you're using another database, check the file `activerecord/test/config.yml` or `activerecord/test/config.example.yml` for default connection information. You can edit `activerecord/test/config.yml` to provide different credentials on your machine if you must, but obviously you should not push any such changes back to Rails.
2016-08-22 13:35:33 -04:00
2018-05-13 15:37:44 -04:00
### Install JavaScript dependencies
2016-08-22 13:35:33 -04:00
2018-05-13 15:37:44 -04:00
If you installed Yarn, you will need to install the javascript dependencies:
2017-08-18 11:31:19 -04:00
```bash
2018-08-16 06:31:24 -04:00
$ yarn install
2017-08-18 11:31:19 -04:00
```
2018-05-27 06:06:11 -04:00
2018-05-13 15:37:44 -04:00
### Install Bundler gem
2018-05-27 06:06:11 -04:00
2018-05-13 15:37:44 -04:00
Get a recent version of [Bundler ](https://bundler.io/ )
2018-05-27 06:06:11 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ gem install bundler
$ gem update bundler
2018-05-27 06:06:11 -04:00
```
2018-05-13 15:37:44 -04:00
and run:
2018-05-27 06:06:11 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ bundle install
2018-05-27 06:06:11 -04:00
```
2018-05-13 15:37:44 -04:00
or:
2018-05-27 06:06:11 -04:00
```bash
2018-05-13 15:37:44 -04:00
$ bundle install --without db
2018-08-09 14:08:31 -04:00
```
2018-05-13 15:37:44 -04:00
if you don't need to run Active Record tests.
2018-08-09 14:08:31 -04:00
2018-05-13 15:37:44 -04:00
### Contribute to Rails
2018-08-21 22:35:09 -04:00
2019-08-09 17:30:15 -04:00
After you've set up everything, read how you can start [contributing ](contributing_to_ruby_on_rails.html#running-an-application-against-your-local-branch ).