Installation-Guide.rst 27.4 KB
Newer Older
1
2
3
Installation Guide
==================

4
This is a guide for building the LightGBM Command Line Interface (CLI). If you want to build the Python-package or R-package please refer to `Python-package`_ and `R-package`_ folders respectively.
5

6
7
8
All instructions below are aimed at compiling the 64-bit version of LightGBM.
It is worth compiling the 32-bit version only in very rare special cases involving environmental limitations.
The 32-bit version is slow and untested, so use it at your own risk and don't forget to adjust some of the commands below when installing.
9

10
11
If you need to build a static library instead of a shared one, you can add ``-DBUILD_STATIC_LIB=ON`` to CMake flags.

12
Users who want to perform benchmarking can make LightGBM output time costs for different internal routines by adding ``-DUSE_TIMETAG=ON`` to CMake flags.
Guolin Ke's avatar
Guolin Ke committed
13

14
It is possible to build LightGBM in debug mode. In this mode all compiler optimizations are disabled and LightGBM performs more checks internally. To enable debug mode you can add ``-DUSE_DEBUG=ON`` to CMake flags or choose ``Debug_*`` configuration (e.g. ``Debug_DLL``, ``Debug_mpi``) in Visual Studio depending on how you are building LightGBM.
Guolin Ke's avatar
Guolin Ke committed
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
.. _sanitizers:

In addition to the debug mode, LightGBM can be built with compiler sanitizers.
To enable them add ``-DUSE_SANITIZER=ON -DENABLED_SANITIZERS="address;leak;undefined"`` to CMake flags.
These values refer to the following supported sanitizers:

- ``address`` - AddressSanitizer (ASan);
- ``leak`` - LeakSanitizer (LSan);
- ``undefined`` - UndefinedBehaviorSanitizer (UBSan);
- ``thread`` - ThreadSanitizer (TSan).

Please note, that ThreadSanitizer cannot be used together with other sanitizers.
For more info and additional sanitizers' parameters please refer to the `following docs`_.
It is very useful to build `C++ unit tests <#build-c-unit-tests>`__ with sanitizers.

31
32
.. _nightly-builds:

33
You can also download the artifacts of the latest successful build on master branch (nightly builds) here: |download artifacts|.
34

35
36
37
38
.. contents:: **Contents**
    :depth: 1
    :local:
    :backlinks: none
39

40
41
42
Windows
~~~~~~~

43
44
45
46
On Windows LightGBM can be built using

- **Visual Studio**;

47
- **CMake** and **VS Build Tools**;
48
49

- **CMake** and **MinGW**.
50

51
52
Visual Studio (or VS Build Tools)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53
54
55
56

With GUI
********

57
1. Install `Visual Studio`_ (2015 or newer).
58

59
2. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
60
61
62

3. Go to ``LightGBM-master/windows`` folder.

63
4. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release`` configuration and click ``BUILD`` -> ``Build Solution (Ctrl+Shift+B)``.
64

65
   If you have errors about **Platform Toolset**, go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
66

67
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release`` folder.
68
69
70
71

From Command Line
*****************

72
1. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
73
74
75

2. Run the following commands:

76
   .. code:: console
77

78
     git clone --recursive https://github.com/microsoft/LightGBM
79
80
81
     cd LightGBM
     mkdir build
     cd build
82
     cmake -A x64 ..
83
84
     cmake --build . --target ALL_BUILD --config Release

85
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
86

87
88
MinGW-w64
^^^^^^^^^
89
90
91
92
93

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

94
   .. code:: console
95

96
     git clone --recursive https://github.com/microsoft/LightGBM
97
98
99
100
101
102
     cd LightGBM
     mkdir build
     cd build
     cmake -G "MinGW Makefiles" ..
     mingw32-make.exe -j4

103
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
104

105
**Note**: You may need to run the ``cmake -G "MinGW Makefiles" ..`` one more time if you encounter the ``sh.exe was found in your PATH`` error.
106

107
It is recommended that you use **Visual Studio** since it has better multithreading efficiency in **Windows** for many-core systems
108
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).
109
110

Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
111

112
113
114
Linux
~~~~~

115
On Linux LightGBM can be built using **CMake** and **gcc** or **Clang**.
116

117
1. Install `CMake`_.
118

119
120
2. Run the following commands:

121
   .. code:: sh
122

123
124
125
126
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
127
128
     cmake ..
     make -j4
129

130
**Note**: glibc >= 2.28 is required.
131

132
133
**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

134
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
Using ``Ninja``
^^^^^^^^^^^^^^^

On Linux, LightGBM can also be built with `Ninja <https://ninja-build.org/>`__ instead of ``make``.

.. code:: sh

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
     cmake -G 'Ninja' ..
     ninja -j2

150
151
macOS
~~~~~
152

153
On macOS LightGBM can be installed using **Homebrew**, or can be built using **CMake** and **Apple Clang** or **gcc**.
154
155
156

Apple Clang
^^^^^^^^^^^
fanliwen's avatar
fanliwen committed
157

158
Only **Apple Clang** version 8.1 or higher is supported.
fanliwen's avatar
fanliwen committed
159

160
161
162
Install Using ``Homebrew``
**************************

163
.. code:: sh
164
165
166
167
168
169

  brew install lightgbm

Build from GitHub
*****************

170
1. Install `CMake`_ (3.16 or higher):
Nikita Titov's avatar
Nikita Titov committed
171

172
   .. code:: sh
Nikita Titov's avatar
Nikita Titov committed
173

174
     brew install cmake
fanliwen's avatar
fanliwen committed
175

176
2. Install **OpenMP**:
fanliwen's avatar
fanliwen committed
177

178
   .. code:: sh
fanliwen's avatar
fanliwen committed
179
180

     brew install libomp
181
182
183

3. Run the following commands:

184
   .. code:: sh
185

186
187
188
189
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
fanliwen's avatar
fanliwen committed
190
191
192
     cmake ..
     make -j4

193
194
gcc
^^^
195

196
1. Install `CMake`_ (3.2 or higher):
197

198
   .. code:: sh
199

200
     brew install cmake
201

202
2. Install **gcc**:
203

204
   .. code:: sh
205

206
207
208
209
     brew install gcc

3. Run the following commands:

210
   .. code:: sh
211

212
213
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
214
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
215
216
     mkdir build
     cd build
217
218
     cmake ..
     make -j4
219

220
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.
221

222
223
224
Docker
~~~~~~

225
Refer to `Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker>`__.
226

227
228
229
230
Build Threadless Version (not Recommended)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The default build version of LightGBM is based on OpenMP.
231
You can build LightGBM without OpenMP support but it is **strongly not recommended**.
232
233
234
235

Windows
^^^^^^^

236
On Windows a version of LightGBM without OpenMP support can be built using
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

- **Visual Studio**;

- **CMake** and **VS Build Tools**;

- **CMake** and **MinGW**.

Visual Studio (or VS Build Tools)
*********************************

With GUI
--------

1. Install `Visual Studio`_ (2015 or newer).

252
2. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
253
254
255
256
257
258
259
260
261
262
263

3. Go to ``LightGBM-master/windows`` folder.

4. Open ``LightGBM.sln`` file with **Visual Studio**.

5. Go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``C/C++`` -> ``Language`` and change the ``OpenMP Support`` property to ``No (/openmp-)``.

6. Get back to the project's main screen, then choose ``Release`` configuration and click ``BUILD`` -> ``Build Solution (Ctrl+Shift+B)``.

   If you have errors about **Platform Toolset**, go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.

264
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release`` folder.
265
266
267
268
269
270
271
272

From Command Line
-----------------

1. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).

2. Run the following commands:

273
   .. code:: console
274

275
     git clone --recursive https://github.com/microsoft/LightGBM
276
277
278
     cd LightGBM
     mkdir build
     cd build
279
     cmake -A x64 -DUSE_OPENMP=OFF ..
280
281
     cmake --build . --target ALL_BUILD --config Release

282
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
283
284
285
286
287
288
289
290

MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Run the following commands:

291
   .. code:: console
292

293
     git clone --recursive https://github.com/microsoft/LightGBM
294
295
296
297
298
299
     cd LightGBM
     mkdir build
     cd build
     cmake -G "MinGW Makefiles" -DUSE_OPENMP=OFF ..
     mingw32-make.exe -j4

300
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
301
302
303
304
305
306

**Note**: You may need to run the ``cmake -G "MinGW Makefiles" -DUSE_OPENMP=OFF ..`` one more time if you encounter the ``sh.exe was found in your PATH`` error.

Linux
^^^^^

307
On Linux a version of LightGBM without OpenMP support can be built using **CMake** and **gcc** or **Clang**.
308
309
310
311
312

1. Install `CMake`_.

2. Run the following commands:

313
   .. code:: sh
314

315
316
317
318
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
319
320
321
322
323
324
325
326
     cmake -DUSE_OPENMP=OFF ..
     make -j4

**Note**: glibc >= 2.14 is required.

macOS
^^^^^

327
On macOS a version of LightGBM without OpenMP support can be built using **CMake** and **Apple Clang** or **gcc**.
328
329
330
331
332
333

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

334
1. Install `CMake`_ (3.16 or higher):
335

336
   .. code:: sh
337
338
339
340
341

     brew install cmake

2. Run the following commands:

342
   .. code:: sh
343

344
345
346
347
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
348
349
350
351
352
353
354
355
     cmake -DUSE_OPENMP=OFF ..
     make -j4

gcc
***

1. Install `CMake`_ (3.2 or higher):

356
   .. code:: sh
357
358
359
360
361

     brew install cmake

2. Install **gcc**:

362
   .. code:: sh
363
364
365
366
367

     brew install gcc

3. Run the following commands:

368
   .. code:: sh
369

370
371
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
372
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
373
374
     mkdir build
     cd build
375
376
377
     cmake -DUSE_OPENMP=OFF ..
     make -j4

378
379
380
Build MPI Version
~~~~~~~~~~~~~~~~~

381
382
The default build version of LightGBM is based on socket. LightGBM also supports MPI.
`MPI`_ is a high performance communication approach with `RDMA`_ support.
383

384
If you need to run a distributed learning application with high performance communication, you can build the LightGBM with MPI support.
385
386
387
388

Windows
^^^^^^^

389
On Windows an MPI version of LightGBM can be built using
390
391
392

- **MS MPI** and **Visual Studio**;

393
- **MS MPI**, **CMake** and **VS Build Tools**.
394

395
396
397
With GUI
********

398
1. You need to install `MS MPI`_ first. Both ``msmpisdk.msi`` and ``msmpisetup.exe`` are needed.
399

400
2. Install `Visual Studio`_ (2015 or newer).
401

402
3. Navigate to one of the releases at https://github.com/microsoft/LightGBM/releases, download ``LightGBM-complete_source_code_zip.zip``, and unzip it.
403
404
405

4. Go to ``LightGBM-master/windows`` folder.

406
5. Open ``LightGBM.sln`` file with **Visual Studio**, choose ``Release_mpi`` configuration and click ``BUILD`` -> ``Build Solution (Ctrl+Shift+B)``.
407

408
   If you have errors about **Platform Toolset**, go to ``PROJECT`` -> ``Properties`` -> ``Configuration Properties`` -> ``General`` and select the toolset installed on your machine.
409

410
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release_mpi`` folder.
411
412
413
414

From Command Line
*****************

415
1. You need to install `MS MPI`_ first. Both ``msmpisdk.msi`` and ``msmpisetup.exe`` are needed.
416

417
2. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
418
419
420

3. Run the following commands:

421
   .. code:: console
422

423
     git clone --recursive https://github.com/microsoft/LightGBM
424
425
426
     cd LightGBM
     mkdir build
     cd build
427
     cmake -A x64 -DUSE_MPI=ON ..
428
429
     cmake --build . --target ALL_BUILD --config Release

430
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
431

432
**Note**: Building MPI version by **MinGW** is not supported due to the miss of MPI library in it.
433
434
435
436

Linux
^^^^^

437
On Linux an MPI version of LightGBM can be built using **Open MPI**, **CMake** and **gcc** or **Clang**.
438

439
1. Install `Open MPI`_.
440

441
2. Install `CMake`_.
442

443
444
3. Run the following commands:

445
   .. code:: sh
446

447
448
449
450
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
451
452
     cmake -DUSE_MPI=ON ..
     make -j4
453
454
455

**Note**: glibc >= 2.14 is required.

456
457
**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

458
459
macOS
^^^^^
460

461
On macOS an MPI version of LightGBM can be built using **Open MPI**, **CMake** and **Apple Clang** or **gcc**.
462

463
464
Apple Clang
***********
465

466
Only **Apple Clang** version 8.1 or higher is supported.
467

468
1. Install `CMake`_ (3.16 or higher):
469

470
   .. code:: sh
471

472
473
474
475
     brew install cmake

2. Install **OpenMP**:

476
   .. code:: sh
477
478
479
480
481

     brew install libomp

3. Install **Open MPI**:

482
   .. code:: sh
483
484
485
486
487

     brew install open-mpi

4. Run the following commands:

488
   .. code:: sh
489

490
491
492
493
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
494
495
496
497
498
499
500
501
     cmake -DUSE_MPI=ON ..
     make -j4

gcc
***

1. Install `CMake`_ (3.2 or higher):

502
   .. code:: sh
503
504
505
506
507

     brew install cmake

2. Install **gcc**:

508
   .. code:: sh
509
510
511
512
513

     brew install gcc

3. Install **Open MPI**:

514
   .. code:: sh
515
516
517
518
519

     brew install open-mpi

4. Run the following commands:

520
   .. code:: sh
521

522
523
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
524
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
525
526
     mkdir build
     cd build
527
528
     cmake -DUSE_MPI=ON ..
     make -j4
529
530
531
532
533
534
535

Build GPU Version
~~~~~~~~~~~~~~~~~

Linux
^^^^^

536
On Linux a GPU version of LightGBM (``device_type=gpu``) can be built using **OpenCL**, **Boost**, **CMake** and **gcc** or **Clang**.
537

538
539
The following dependencies should be installed before compilation:

540
-  **OpenCL** 1.2 headers and libraries, which is usually provided by GPU manufacture.
541

542
   The generic OpenCL ICD packages (for example, Debian package ``ocl-icd-libopencl1`` and ``ocl-icd-opencl-dev``) can also be used.
543

544
-  **libboost** 1.56 or later (1.61 or later is recommended).
545
546
547
548
549

   We use Boost.Compute as the interface to GPU, which is part of the Boost library since version 1.61. However, since we include the source code of Boost.Compute as a submodule, we only require the host has Boost 1.56 or later installed. We also use Boost.Align for memory allocation. Boost.Compute requires Boost.System and Boost.Filesystem to store offline kernel cache.

   The following Debian packages should provide necessary Boost libraries: ``libboost-dev``, ``libboost-system-dev``, ``libboost-filesystem-dev``.

550
-  **CMake** 3.2 or later.
551
552
553

To build LightGBM GPU version, run the following commands:

554
.. code:: sh
555

556
557
558
559
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
  mkdir build
  cd build
560
  cmake -DUSE_GPU=1 ..
561
562
  # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
  # cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..
563
564
  make -j4

565
566
567
568
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

569
570
571
Windows
^^^^^^^

572
On Windows a GPU version of LightGBM (``device_type=gpu``) can be built using **OpenCL**, **Boost**, **CMake** and **VS Build Tools** or **MinGW**.
573

574
If you use **MinGW**, the build procedure is similar to the build on Linux. Refer to `GPU Windows Compilation <./GPU-Windows.rst>`__ to get more details.
575

576
577
Following procedure is for the **MSVC** (Microsoft Visual C++) build.

578
1. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is installed).
579
580
581
582
583

2. Install **OpenCL** for Windows. The installation depends on the brand (NVIDIA, AMD, Intel) of your GPU card.

   - For running on Intel, get `Intel SDK for OpenCL`_.

584
   - For running on AMD, get AMD APP SDK.
585
586
587

   - For running on NVIDIA, get `CUDA Toolkit`_.

588
589
   Further reading and correspondence table: `GPU SDK Correspondence and Device Targeting Table <./GPU-Targets.rst>`__.

Nikita Titov's avatar
Nikita Titov committed
590
3. Install `Boost Binaries`_.
591

592
   **Note**: Match your Visual C++ version:
593

594
595
   Visual Studio 2015 -> ``msvc-14.0-64.exe``,

596
597
   Visual Studio 2017 -> ``msvc-14.1-64.exe``,

598
599
600
   Visual Studio 2019 -> ``msvc-14.2-64.exe``,

   Visual Studio 2022 -> ``msvc-14.3-64.exe``.
601
602
603

4. Run the following commands:

604
   .. code:: console
605

606
     git clone --recursive https://github.com/microsoft/LightGBM
607
608
609
     cd LightGBM
     mkdir build
     cd build
610
611
612
     cmake -A x64 -DUSE_GPU=1 -DBOOST_ROOT=C:/local/boost_1_63_0 -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0 ..
     # if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
     # cmake -A x64 -DUSE_GPU=1 -DBOOST_ROOT=C:/local/boost_1_63_0 -DBOOST_LIBRARYDIR=C:/local/boost_1_63_0/lib64-msvc-14.0 -DOpenCL_LIBRARY="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/lib/x64/OpenCL.lib" -DOpenCL_INCLUDE_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.0/include" ..
613
614
     cmake --build . --target ALL_BUILD --config Release

615
   **Note**: ``C:/local/boost_1_63_0`` and ``C:/local/boost_1_63_0/lib64-msvc-14.0`` are locations of your **Boost** binaries (assuming you've downloaded 1.63.0 version for Visual Studio 2015).
616
617
618
619

Docker
^^^^^^

620
Refer to `GPU Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker/gpu>`__.
621

622
623
Build CUDA Version
~~~~~~~~~~~~~~~~~~
624

625
The `original GPU build <#build-gpu-version>`__ of LightGBM (``device_type=gpu``) is based on OpenCL.
626

627
The CUDA-based build (``device_type=cuda``) is a separate implementation and requires an NVIDIA graphics card with compute capability 6.0 and higher. It should be considered experimental, and we suggest using it only when it is impossible to use OpenCL version (for example, on IBM POWER microprocessors).
628
629
630
631
632
633

**Note**: only Linux is supported, other operating systems are not supported yet.

Linux
^^^^^

634
On Linux a CUDA version of LightGBM can be built using **CUDA**, **CMake** and **gcc** or **Clang**.
635
636
637

The following dependencies should be installed before compilation:

638
-  **CUDA** 11.0 or later libraries. Please refer to `this detailed guide`_. Pay great attention to the minimum required versions of host compilers listed in the table from that guide and use only recommended versions of compilers.
639
640
641
642
643

-  **CMake** 3.16 or later.

To build LightGBM CUDA version, run the following commands:

644
.. code:: sh
645

646
647
648
649
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
  mkdir build
  cd build
650
651
652
  cmake -DUSE_CUDA=1 ..
  make -j4

653
654
655
656
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

657
658
659
Build HDFS Version
~~~~~~~~~~~~~~~~~~

660
The HDFS version of LightGBM was tested on CDH-5.14.4 cluster.
661
662
663
664

Linux
^^^^^

665
On Linux a HDFS version of LightGBM can be built using **CMake** and **gcc**.
666

667
1. Install `CMake`_.
fanliwen's avatar
fanliwen committed
668
669
670

2. Run the following commands:

671
   .. code:: sh
fanliwen's avatar
fanliwen committed
672

673
674
675
676
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
fanliwen's avatar
fanliwen committed
677
     cmake -DUSE_HDFS=ON ..
678
679
680
681
682
683
     # if you have installed HDFS to a customized location, you should specify paths to HDFS headers (hdfs.h) and library (libhdfs.so) like the following:
     # cmake \
     #   -DUSE_HDFS=ON \
     #   -DHDFS_LIB="/opt/cloudera/parcels/CDH-5.14.4-1.cdh5.14.4.p0.3/lib64/libhdfs.so" \
     #   -DHDFS_INCLUDE_DIR="/opt/cloudera/parcels/CDH-5.14.4-1.cdh5.14.4.p0.3/include/" \
     #   ..
fanliwen's avatar
fanliwen committed
684
685
     make -j4

686
687
688
689
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

690
691
692
Build Java Wrapper
~~~~~~~~~~~~~~~~~~

693
Using the following instructions you can generate a JAR file containing the LightGBM `C API <./Development-Guide.rst#c-api>`__ wrapped by **SWIG**.
694
695
696
697

Windows
^^^^^^^

698
On Windows a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **VS Build Tools** or **MinGW**.
699

700
701
VS Build Tools
**************
702

703
1. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).
704
705
706
707
708

2. Install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).

3. Run the following commands:

709
   .. code:: console
710

711
     git clone --recursive https://github.com/microsoft/LightGBM
712
713
714
     cd LightGBM
     mkdir build
     cd build
715
     cmake -A x64 -DUSE_SWIG=ON ..
716
717
     cmake --build . --target ALL_BUILD --config Release

718
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/Release`` folder.
719
720
721
722
723
724
725
726
727
728

MinGW-w64
*********

1. Install `Git for Windows`_, `CMake`_ and `MinGW-w64`_.

2. Install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).

3. Run the following commands:

729
   .. code:: console
730

731
     git clone --recursive https://github.com/microsoft/LightGBM
732
733
734
735
736
737
     cd LightGBM
     mkdir build
     cd build
     cmake -G "MinGW Makefiles" -DUSE_SWIG=ON ..
     mingw32-make.exe -j4

738
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/`` folder.
739
740
741

**Note**: You may need to run the ``cmake -G "MinGW Makefiles" -DUSE_SWIG=ON ..`` one more time if you encounter the ``sh.exe was found in your PATH`` error.

742
It is recommended to use **VS Build Tools (Visual Studio)** since it has better multithreading efficiency in **Windows** for many-core systems
743
744
(see `Question 4 <./FAQ.rst#i-am-using-windows-should-i-use-visual-studio-or-mingw-for-compiling-lightgbm>`__ and `Question 8 <./FAQ.rst#cpu-usage-is-low-like-10-in-windows-when-using-lightgbm-on-very-large-datasets-with-many-core-systems>`__).

745
746
Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.

747
748
749
Linux
^^^^^

750
On Linux a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **gcc** or **Clang**.
751

752
1. Install `CMake`_, `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).
753

754
2. Run the following commands:
755

756
   .. code:: sh
757

758
759
760
761
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
762
     cmake -DUSE_SWIG=ON ..
763
     make -j4
764

765
766
767
768
**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).

769
770
771
macOS
^^^^^

772
On macOS a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **Apple Clang** or **gcc**.
773
774
775
776
777
778
779
780
781

First, install `SWIG`_ and **Java** (also make sure that ``JAVA_HOME`` is set properly).
Then, either follow the **Apple Clang** or **gcc** installation instructions below.

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

782
1. Install `CMake`_ (3.16 or higher):
783

784
   .. code:: sh
785
786
787
788
789

     brew install cmake

2. Install **OpenMP**:

790
   .. code:: sh
791
792
793
794
795

     brew install libomp

3. Run the following commands:

796
   .. code:: sh
797

798
799
800
801
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
802
803
804
805
806
807
808
809
     cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
     make -j4

gcc
***

1. Install `CMake`_ (3.2 or higher):

810
   .. code:: sh
811
812
813
814
815

     brew install cmake

2. Install **gcc**:

816
   .. code:: sh
817
818
819
820
821

     brew install gcc

3. Run the following commands:

822
   .. code:: sh
823

824
825
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
826
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
827
828
     mkdir build
     cd build
829
830
831
832
833
     cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
     make -j4

Also, you may want to read `gcc Tips <./gcc-Tips.rst>`__.

834
835
836
837
838
839
840
841
842
843
844
845
Build C++ Unit Tests
~~~~~~~~~~~~~~~~~~~~

Windows
^^^^^^^

On Windows, C++ unit tests of LightGBM can be built using **CMake** and **VS Build Tools**.

1. Install `Git for Windows`_, `CMake`_ (3.8 or higher) and `VS Build Tools`_ (**VS Build Tools** is not needed if **Visual Studio** (2015 or newer) is already installed).

2. Run the following commands:

846
   .. code:: console
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
     cmake -A x64 -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
     cmake --build . --target testlightgbm --config Debug

The ``.exe`` file will be in ``LightGBM/Debug`` folder.

Linux
^^^^^

On Linux a C++ unit tests of LightGBM can be built using **CMake** and **gcc** or **Clang**.

1. Install `CMake`_.

2. Run the following commands:

866
   .. code:: sh
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
     cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
     make testlightgbm -j4

**Note**: glibc >= 2.14 is required.

macOS
^^^^^

On macOS a C++ unit tests of LightGBM can be built using **CMake** and **Apple Clang** or **gcc**.

Apple Clang
***********

Only **Apple Clang** version 8.1 or higher is supported.

1. Install `CMake`_ (3.16 or higher):

889
   .. code:: sh
890
891
892
893
894

     brew install cmake

2. Run the following commands:

895
   .. code:: sh
896
897
898
899
900
901
902
903
904
905
906
907
908

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
     cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
     make testlightgbm -j4

gcc
***

1. Install `CMake`_ (3.2 or higher):

909
   .. code:: sh
910
911
912
913
914

     brew install cmake

2. Install **gcc**:

915
   .. code:: sh
916
917
918
919
920

     brew install gcc

3. Run the following commands:

921
   .. code:: sh
922
923
924
925
926
927
928
929
930

     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
     mkdir build
     cd build
     cmake -DBUILD_CPP_TEST=ON -DUSE_OPENMP=OFF ..
     make testlightgbm -j4

931

932
933
934
.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
   :target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html

935
.. _Python-package: https://github.com/microsoft/LightGBM/tree/master/python-package
936

937
.. _R-package: https://github.com/microsoft/LightGBM/tree/master/R-package
938

939
.. _Visual Studio: https://visualstudio.microsoft.com/downloads/
940
941
942
943
944

.. _Git for Windows: https://git-scm.com/download/win

.. _CMake: https://cmake.org/

945
.. _VS Build Tools: https://visualstudio.microsoft.com/downloads/
946

947
.. _MinGW-w64: https://www.mingw-w64.org/downloads/
948
949
950
951
952

.. _MPI: https://en.wikipedia.org/wiki/Message_Passing_Interface

.. _RDMA: https://en.wikipedia.org/wiki/Remote_direct_memory_access

953
.. _MS MPI: https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi-release-notes
954
955
956
957
958
959
960

.. _Open MPI: https://www.open-mpi.org/

.. _Intel SDK for OpenCL: https://software.intel.com/en-us/articles/opencl-drivers

.. _CUDA Toolkit: https://developer.nvidia.com/cuda-downloads

961
.. _Boost Binaries: https://sourceforge.net/projects/boost/files/boost-binaries/
962
963

.. _SWIG: http://www.swig.org/download.html
964
965

.. _this detailed guide: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
966
967

.. _following docs: https://github.com/google/sanitizers/wiki