]> git.openstreetmap.org Git - rails.git/blob - doc/MANUAL_INSTALL.md
Merge remote-tracking branch 'upstream/pull/6458'
[rails.git] / doc / MANUAL_INSTALL.md
1 # Manual Installation Guide
2
3 These instructions are based on Ubuntu 24.04 LTS, though the OSMF servers are currently running Debian 12. The instructions also work, with only minor amendments, for all other current Ubuntu releases, Fedora and macOS.
4
5 ## Prerequisites
6
7 Many of the dependencies are managed through the standard Ruby on Rails mechanisms - i.e. Ruby gems specified in the Gemfile and installed using Bundler. Some system packages are also required before you can get the various gems installed.
8
9 **Minimum requirements:**
10 * Ruby 3.2+
11 * PostgreSQL 13+
12 * Bundler (see note below about [developer Ruby setup](#ruby-version-manager-optional))
13 * JavaScript Runtime
14
15 ## Step 1: Install System Dependencies
16
17 ### Ubuntu 24.04 LTS
18
19 ```bash
20 sudo apt-get update
21 sudo apt-get install ruby ruby-dev ruby-bundler \
22                      libvips-dev libxml2-dev libxslt1-dev \
23                      nodejs build-essential git-core \
24                      postgresql postgresql-contrib libpq-dev \
25                      libsasl2-dev libffi-dev libgd-dev \
26                      libarchive-dev libyaml-dev libbz2-dev npm
27 sudo npm install --global yarn
28 ```
29
30 > [!TIP]
31 > On Ubuntu 24.04, you may need to start PostgreSQL:
32 >
33 > ```bash
34 > sudo systemctl start postgresql.service
35 > ```
36
37 ### Fedora
38
39 ```bash
40 sudo dnf install ruby ruby-devel rubygem-rdoc rubygem-bundler \
41                  rubygems libxml2-devel nodejs gcc gcc-c++ git \
42                  postgresql postgresql-server \
43                  postgresql-contrib libpq-devel \
44                  perl-podlators libffi-devel gd-devel \
45                  libarchive-devel libyaml-devel bzip2-devel \
46                  nodejs-yarn vips-devel
47 ```
48
49 On Fedora, if you didn't already have PostgreSQL installed then create a PostgreSQL instance and start the server:
50
51 ```bash
52 sudo postgresql-setup initdb
53 sudo systemctl start postgresql.service
54 ```
55
56 Optionally set PostgreSQL to start on boot:
57
58 ```bash
59 sudo systemctl enable postgresql.service
60 ```
61
62 ### macOS
63
64 For macOS, you will need [Xcode Command Line Tools](https://mac.install.guide/commandlinetools/); macOS 14 (Sonoma) or later; and some familiarity with Unix development via the Terminal.
65
66 **Installing PostgreSQL:**
67
68 * Install Postgres.app from https://postgresapp.com/
69 * Make sure that you've initialized and started Postgresql from the app (there should be a little elephant icon in your systray).
70 * Add PostgreSQL to your path, by editing your profile:
71
72 ```bash
73 nano ~/.profile
74 ```
75
76 and adding:
77
78 ```bash
79 export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
80 ```
81
82 After this, you may need to start a new shell window, or source the profile again by running `. ~/.profile`.
83
84 **Installing other dependencies:**
85
86 * Install Homebrew from https://brew.sh/
87 * Install system dependencies, including Ruby:
88 ```bash
89 brew install ruby libxml2 gd yarn pngcrush optipng \
90              pngquant jhead jpegoptim gifsicle svgo \
91              advancecomp vips
92 ```
93 * Install Bundler: `gem install bundler` (you might need to `sudo gem install bundler` if you get an error about permissions - or see note below about [developer Ruby setup](#ruby-version-manager-optional))
94
95 You will need to tell `bundler` that `libxml2` is installed in a Homebrew location. If it uses the system-installed one then you will get errors installing the `libxml-ruby` gem later on.
96
97 ```bash
98 bundle config build.libxml-ruby --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config
99 ```
100
101 If you want to run the tests, you need `geckodriver` as well:
102
103 ```bash
104 brew install geckodriver
105 ```
106
107 > [!NOTE]
108 > OS X does not have a /home directory by default, so if you are using the GPX functions, you will need to change the directories specified in config/application.yml.
109
110 ## Step 2: Clone the Repository
111
112 The repository is reasonably large (~560MB) and it's unlikely that you'll need the full history. Therefore you can probably do with a shallow clone (~100MB):
113 ```bash
114 git clone --depth=1 https://github.com/openstreetmap/openstreetmap-website.git
115 ```
116
117 If you want to add in the full history later on, perhaps to run `git blame` or `git log`, run `git fetch --unshallow`.
118
119 > [!TIP]
120 > To download the full history from the start, run:
121 > ```bash
122 > git clone https://github.com/openstreetmap/openstreetmap-website.git
123 > ```
124
125 ## Step 3: Install Application Dependencies
126
127 ### Ruby gems
128
129 We use [Bundler](https://bundler.io/) to manage the rubygems required for the project.
130
131 ```bash
132 cd openstreetmap-website
133 bundle install
134 ```
135
136 ### Node.js modules
137
138 We use [Yarn](https://yarnpkg.com/) to manage the Node.js modules required for the project.
139
140 ```bash
141 bundle exec bin/yarn install
142 ```
143
144 ## Step 4: Prepare Configuration Files
145
146 ### Local settings file
147
148 > [!NOTE]
149 > This is a workaround. [See issues/2185 for details](https://github.com/openstreetmap/openstreetmap-website/issues/2185#issuecomment-508676026).
150
151 ```bash
152 touch config/settings.local.yml
153 ```
154
155 ### Storage setup
156
157 `openstreetmap-website` needs to be configured with an object storage facility - for development and testing purposes you can use the example configuration:
158
159 ```bash
160 cp config/example.storage.yml config/storage.yml
161 ```
162
163 ## Step 5: Database Setup
164
165 `openstreetmap-website` uses three databases - one for development, one for testing, and one for production. The database-specific configuration options are stored in `config/database.yml`, which we need to create from the example template.
166
167 ```bash
168 cp config/example.database.yml config/database.yml
169 ```
170
171 > [!IMPORTANT]
172 > PostgreSQL is configured to, by default, accept local connections without requiring a username or password. This is fine for development. If you wish to set up your database differently, then you should change the values found in the `config/database.yml` file, and amend the instructions below as appropriate.
173
174 ### PostgreSQL account setup
175
176 We need to create a PostgreSQL role (i.e. user account) for your current user, and it needs to be a superuser so that we can create more databases.
177
178 ```bash
179 sudo -u postgres -i
180 createuser -s <username>
181 exit
182 ```
183
184 ### Create the databases
185
186 To create the three databases - for development, testing and production - run:
187
188 ```bash
189 bundle exec rails db:create
190 ```
191
192 ### Database structure
193
194 To create all the tables, indexes and constraints, run:
195
196 ```bash
197 bundle exec rails db:migrate
198 ```
199
200 ## Validate Your Installation
201
202 ### Running the tests
203
204 To ensure that everything is set up properly, you should now run:
205
206 ```bash
207 bundle exec rails test:all
208 ```
209
210 This test will take a few minutes, reporting tests run, assertions, and any errors. If you receive no errors, then your installation is successful.
211
212 > [!NOTE]
213 > The unit tests may output parser errors related to "Attribute lat redefined." These can be ignored.
214
215 ### Starting the server
216
217 Rails comes with a built-in webserver, so that you can test on your own machine without needing a server. Run
218
219 ```bash
220 bundle exec rails server
221 ```
222
223 You can now view the site in your favourite web-browser at [http://localhost:3000/](http://localhost:3000/)
224
225 > [!NOTE]
226 > The OSM map tiles you see aren't created from your local database - they are the production map tiles, served from a separate service over the Internet.
227
228 ## What's Next?
229
230 🎉 **Congratulations!** You have successfully installed the OpenStreetMap website.
231
232 **Next steps:**
233 * **Configuration:** See [CONFIGURE.md](CONFIGURE.md) for populating the database with data, creating users, setting up OAuth, and other configuration tasks.
234 * **Contributing:** Check out [CONTRIBUTING.md](../CONTRIBUTING.md) for coding style guidelines, testing procedures, and how to submit your contributions.
235
236 ## Ruby Version Manager (Optional)
237
238 For simplicity, this document explains how to install all the website dependencies as "system" dependencies. While this can be simpler and faster, you might want more control over the process or the ability to install multiple different versions of Ruby alongside each other.
239
240 Several tools exist that allow managing multiple different Ruby versions on the same computer. They also provide the additional advantage that the installs are all in your home directory, so you don't need administrator permissions. These tools are typically known as "version managers".
241
242 This section shows how to install Ruby and Bundler with [`rbenv`](https://github.com/rbenv/rbenv), which is one of these tools. If you choose to install Ruby and Bundler via `rbenv`, then you do not need to install the system libraries for Ruby:
243
244 * For Ubuntu, you do not need to install the following packages: `ruby ruby-dev ruby-bundler`,
245 * For Fedora, you do not need to install the following packages: `ruby ruby-devel rubygem-rdoc rubygem-bundler rubygems`
246 * For macOS, you do not need to `brew install ruby`
247
248 > [!IMPORTANT]
249 > On macOS, make sure you've installed a version of Ruby using `rbenv` before running `gem install bundler`!
250
251 After installing a version of Ruby with `rbenv` (the latest stable version is a good place to start), you will need to make that the default. From inside the `openstreetmap-website` directory, run:
252
253 ```bash
254 rbenv local $VERSION
255 ```
256
257 Where `$VERSION` is the version you installed. You can see a list of available versions by running `rbenv versions`. Then install bundler:
258
259 ```bash
260 gem install bundler
261 ```
262
263 You should now be able to proceed with the rest of the installation. If you're on macOS, make sure you set up the [config override for the libxml2 location](#macos-click-to-expand) _after_ installing bundler.