Installation-Guide.rst 22.8 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
You can also download the artifacts of the latest successful build on master branch (nightly builds) here: |download artifacts|.
17

18
19
20
21
.. contents:: **Contents**
    :depth: 1
    :local:
    :backlinks: none
22

23
24
25
Windows
~~~~~~~

26
27
28
29
On Windows LightGBM can be built using

- **Visual Studio**;

30
- **CMake** and **VS Build Tools**;
31
32

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

34
35
Visual Studio (or VS Build Tools)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36
37
38
39

With GUI
********

40
1. Install `Visual Studio`_ (2015 or newer).
41
42
43
44
45

2. Download `zip archive`_ and unzip it.

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

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

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

50
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release`` folder.
51
52
53
54

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

55
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).
56
57
58
59
60

2. Run the following commands:

   .. code::

61
     git clone --recursive https://github.com/microsoft/LightGBM
62
63
64
     cd LightGBM
     mkdir build
     cd build
65
     cmake -A x64 ..
66
67
     cmake --build . --target ALL_BUILD --config Release

68
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
69

70
71
MinGW-w64
^^^^^^^^^
72
73
74
75
76
77
78

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

2. Run the following commands:

   .. code::

79
     git clone --recursive https://github.com/microsoft/LightGBM
80
81
82
83
84
85
     cd LightGBM
     mkdir build
     cd build
     cmake -G "MinGW Makefiles" ..
     mingw32-make.exe -j4

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

88
**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.
89

90
It is recommended that you use **Visual Studio** since it has better multithreading efficiency in **Windows** for many-core systems
91
(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>`__).
92
93

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

95
96
97
Linux
~~~~~

98
On Linux LightGBM can be built using **CMake** and **gcc** or **Clang**.
99

100
1. Install `CMake`_.
101

102
103
104
105
2. Run the following commands:

   .. code::

106
107
108
109
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
110
111
     cmake ..
     make -j4
112
113
114

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

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

117
118
macOS
~~~~~
119

120
On macOS LightGBM can be installed using **Homebrew**, or can be built using **CMake** and **Apple Clang** or **gcc**.
121
122
123

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

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

127
128
129
130
131
132
133
134
135
136
Install Using ``Homebrew``
**************************

.. code::

  brew install lightgbm

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

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

139
   .. code::
Nikita Titov's avatar
Nikita Titov committed
140

141
     brew install cmake
fanliwen's avatar
fanliwen committed
142

143
2. Install **OpenMP**:
fanliwen's avatar
fanliwen committed
144
145
146
147

   .. code::

     brew install libomp
148
149
150
151
152

3. Run the following commands:

   .. code::

153
154
155
156
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
fanliwen's avatar
fanliwen committed
157
158
159
     cmake ..
     make -j4

160
161
gcc
^^^
162

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

165
   .. code::
166

167
     brew install cmake
168

169
2. Install **gcc**:
170

171
   .. code::
172

173
174
175
176
177
178
     brew install gcc

3. Run the following commands:

   .. code::

179
180
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
181
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
182
183
     mkdir build
     cd build
184
185
     cmake ..
     make -j4
186

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

189
190
191
Docker
~~~~~~

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

194
195
196
197
Build Threadless Version (not Recommended)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The default build version of LightGBM is based on OpenMP.
198
You can build LightGBM without OpenMP support but it is **strongly not recommended**.
199
200
201
202

Windows
^^^^^^^

203
On Windows a version of LightGBM without OpenMP support can be built using
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

- **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).

2. Download `zip archive`_ and unzip it.

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.

231
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release`` folder.
232
233
234
235
236
237
238
239
240
241

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:

   .. code::

242
     git clone --recursive https://github.com/microsoft/LightGBM
243
244
245
     cd LightGBM
     mkdir build
     cd build
246
     cmake -A x64 -DUSE_OPENMP=OFF ..
247
248
     cmake --build . --target ALL_BUILD --config Release

249
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
250
251
252
253
254
255
256
257
258
259

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

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

2. Run the following commands:

   .. code::

260
     git clone --recursive https://github.com/microsoft/LightGBM
261
262
263
264
265
266
     cd LightGBM
     mkdir build
     cd build
     cmake -G "MinGW Makefiles" -DUSE_OPENMP=OFF ..
     mingw32-make.exe -j4

267
The ``.exe`` and ``.dll`` files will be in ``LightGBM/`` folder.
268
269
270
271
272
273

**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
^^^^^

274
On Linux a version of LightGBM without OpenMP support can be built using **CMake** and **gcc** or **Clang**.
275
276
277
278
279
280
281

1. Install `CMake`_.

2. Run the following commands:

   .. code::

282
283
284
285
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
286
287
288
289
290
291
292
293
     cmake -DUSE_OPENMP=OFF ..
     make -j4

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

macOS
^^^^^

294
On macOS a version of LightGBM without OpenMP support can be built using **CMake** and **Apple Clang** or **gcc**.
295
296
297
298
299
300

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

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

301
1. Install `CMake`_ (3.16 or higher):
302
303
304
305
306
307
308
309
310

   .. code::

     brew install cmake

2. Run the following commands:

   .. code::

311
312
313
314
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
     cmake -DUSE_OPENMP=OFF ..
     make -j4

gcc
***

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

   .. code::

     brew install cmake

2. Install **gcc**:

   .. code::

     brew install gcc

3. Run the following commands:

   .. code::

337
338
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
339
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
340
341
     mkdir build
     cd build
342
343
344
     cmake -DUSE_OPENMP=OFF ..
     make -j4

345
346
347
Build MPI Version
~~~~~~~~~~~~~~~~~

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

351
If you need to run a distributed learning application with high performance communication, you can build the LightGBM with MPI support.
352
353
354
355

Windows
^^^^^^^

356
On Windows an MPI version of LightGBM can be built using
357
358
359

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

360
- **MS MPI**, **CMake** and **VS Build Tools**.
361

362
363
364
With GUI
********

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

367
2. Install `Visual Studio`_ (2015 or newer).
368
369
370
371
372

3. Download `zip archive`_ and unzip it.

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

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

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

377
The ``.exe`` file will be in ``LightGBM-master/windows/x64/Release_mpi`` folder.
378
379
380
381

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

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

384
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).
385
386
387
388
389

3. Run the following commands:

   .. code::

390
     git clone --recursive https://github.com/microsoft/LightGBM
391
392
393
     cd LightGBM
     mkdir build
     cd build
394
     cmake -A x64 -DUSE_MPI=ON ..
395
396
     cmake --build . --target ALL_BUILD --config Release

397
The ``.exe`` and ``.dll`` files will be in ``LightGBM/Release`` folder.
398

399
**Note**: Building MPI version by **MinGW** is not supported due to the miss of MPI library in it.
400
401
402
403

Linux
^^^^^

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

406
1. Install `Open MPI`_.
407

408
2. Install `CMake`_.
409

410
411
412
413
3. Run the following commands:

   .. code::

414
415
416
417
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
418
419
     cmake -DUSE_MPI=ON ..
     make -j4
420
421
422

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

423
424
macOS
^^^^^
425

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

428
429
Apple Clang
***********
430

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

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

435
   .. code::
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
     brew install cmake

2. Install **OpenMP**:

   .. code::

     brew install libomp

3. Install **Open MPI**:

   .. code::

     brew install open-mpi

4. Run the following commands:

   .. code::

455
456
457
458
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
     cmake -DUSE_MPI=ON ..
     make -j4

gcc
***

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

   .. code::

     brew install cmake

2. Install **gcc**:

   .. code::

     brew install gcc

3. Install **Open MPI**:

   .. code::

     brew install open-mpi

4. Run the following commands:

   .. code::

487
488
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
489
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
490
491
     mkdir build
     cd build
492
493
     cmake -DUSE_MPI=ON ..
     make -j4
494
495
496
497
498
499
500

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

Linux
^^^^^

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

503
504
The following dependencies should be installed before compilation:

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

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

509
-  **libboost** 1.56 or later (1.61 or later is recommended).
510
511
512
513
514

   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``.

515
-  **CMake** 3.2 or later.
516
517
518
519
520

To build LightGBM GPU version, run the following commands:

.. code::

521
522
523
524
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
  mkdir build
  cd build
525
  cmake -DUSE_GPU=1 ..
526
527
  # 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/ ..
528
529
530
531
532
  make -j4

Windows
^^^^^^^

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

535
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.
536

537
538
Following procedure is for the **MSVC** (Microsoft Visual C++) build.

539
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).
540
541
542
543
544

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`_.

545
   - For running on AMD, get AMD APP SDK.
546
547
548

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

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

Nikita Titov's avatar
Nikita Titov committed
551
3. Install `Boost Binaries`_.
552

553
   **Note**: Match your Visual C++ version:
554
555
556
   
   Visual Studio 2015 -> ``msvc-14.0-64.exe``,

557
558
559
   Visual Studio 2017 -> ``msvc-14.1-64.exe``,

   Visual Studio 2019 -> ``msvc-14.2-64.exe``.
560
561
562
563
564

4. Run the following commands:

   .. code::

565
     git clone --recursive https://github.com/microsoft/LightGBM
566
567
568
     cd LightGBM
     mkdir build
     cd build
569
570
571
     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" ..
572
573
     cmake --build . --target ALL_BUILD --config Release

574
   **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).
575
576
577
578

Docker
^^^^^^

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

581
582
583
Build CUDA Version (Experimental)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

586
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).
587
588
589
590
591
592

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

Linux
^^^^^

593
On Linux a CUDA version of LightGBM can be built using **CUDA**, **CMake** and **gcc** or **Clang**.
594
595
596

The following dependencies should be installed before compilation:

597
-  **CUDA** 9.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.
598
599
600
601
602
603
604

-  **CMake** 3.16 or later.

To build LightGBM CUDA version, run the following commands:

.. code::

605
606
607
608
  git clone --recursive https://github.com/microsoft/LightGBM
  cd LightGBM
  mkdir build
  cd build
609
610
611
  cmake -DUSE_CUDA=1 ..
  make -j4

612
613
614
Build HDFS Version
~~~~~~~~~~~~~~~~~~

615
The HDFS version of LightGBM was tested on CDH-5.14.4 cluster.
616
617
618
619

Linux
^^^^^

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

622
1. Install `CMake`_.
fanliwen's avatar
fanliwen committed
623
624
625
626
627

2. Run the following commands:

   .. code::

628
629
630
631
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
fanliwen's avatar
fanliwen committed
632
     cmake -DUSE_HDFS=ON ..
633
634
635
636
637
638
     # 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
639
640
     make -j4

641
642
643
Build Java Wrapper
~~~~~~~~~~~~~~~~~~

644
Using the following instructions you can generate a JAR file containing the LightGBM `C API <./Development-Guide.rst#c-api>`__ wrapped by **SWIG**.
645
646
647
648

Windows
^^^^^^^

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

651
652
VS Build Tools
**************
653

654
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).
655
656
657
658
659
660
661

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

3. Run the following commands:

   .. code::

662
     git clone --recursive https://github.com/microsoft/LightGBM
663
664
665
     cd LightGBM
     mkdir build
     cd build
666
     cmake -A x64 -DUSE_SWIG=ON ..
667
668
     cmake --build . --target ALL_BUILD --config Release

669
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/Release`` folder.
670
671
672
673
674
675
676
677
678
679
680
681

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:

   .. code::

682
     git clone --recursive https://github.com/microsoft/LightGBM
683
684
685
686
687
688
     cd LightGBM
     mkdir build
     cd build
     cmake -G "MinGW Makefiles" -DUSE_SWIG=ON ..
     mingw32-make.exe -j4

689
The ``.jar`` file will be in ``LightGBM/build`` folder and the ``.dll`` files will be in ``LightGBM/`` folder.
690
691
692

**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.

693
It is recommended to use **VS Build Tools (Visual Studio)** since it has better multithreading efficiency in **Windows** for many-core systems
694
695
(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>`__).

696
697
698

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

699
700
701
Linux
^^^^^

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

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

706
2. Run the following commands:
707

708
709
   .. code::

710
711
712
713
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
714
     cmake -DUSE_SWIG=ON ..
715
     make -j4
716

717
718
719
macOS
^^^^^

720
On macOS a Java wrapper of LightGBM can be built using **Java**, **SWIG**, **CMake** and **Apple Clang** or **gcc**.
721
722
723
724
725
726
727
728
729

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.

730
1. Install `CMake`_ (3.16 or higher):
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745

   .. code::

     brew install cmake

2. Install **OpenMP**:

   .. code::

     brew install libomp

3. Run the following commands:

   .. code::

746
747
748
749
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
     mkdir build
     cd build
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
     cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
     make -j4

gcc
***

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

   .. code::

     brew install cmake

2. Install **gcc**:

   .. code::

     brew install gcc

3. Run the following commands:

   .. code::

772
773
     git clone --recursive https://github.com/microsoft/LightGBM
     cd LightGBM
774
     export CXX=g++-7 CC=gcc-7  # replace "7" with version of gcc installed on your machine
775
776
     mkdir build
     cd build
777
778
779
780
781
782
     cmake -DUSE_SWIG=ON -DAPPLE_OUTPUT_DYLIB=ON ..
     make -j4

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


783
784
785
.. |download artifacts| image:: ./_static/images/artifacts-not-available.svg
   :target: https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html

786
.. _Python-package: https://github.com/microsoft/LightGBM/tree/master/python-package
787

788
.. _R-package: https://github.com/microsoft/LightGBM/tree/master/R-package
789

790
.. _zip archive: https://github.com/microsoft/LightGBM/archive/master.zip
791

792
.. _Visual Studio: https://visualstudio.microsoft.com/downloads/
793
794
795
796
797

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

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

798
.. _VS Build Tools: https://visualstudio.microsoft.com/downloads/
799
800
801
802
803
804
805

.. _MinGW-w64: https://mingw-w64.org/doku.php/download

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

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

806
.. _MS MPI: https://www.microsoft.com/en-us/download/details.aspx?id=100593
807
808
809
810
811
812
813

.. _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

814
.. _Boost Binaries: https://sourceforge.net/projects/boost/files/boost-binaries/
815
816

.. _SWIG: http://www.swig.org/download.html
817
818

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