|
| 1 | +.. _c-get-started-download-and-install: |
| 2 | + |
| 3 | +==================== |
| 4 | +Download and Install |
| 5 | +==================== |
| 6 | + |
| 7 | +Download the {+driver-short+} |
| 8 | +---------------------- |
| 9 | + |
| 10 | +The {+driver-short+} consists of two libraries: ``libbson`` and |
| 11 | +``libmongoc``. In this guide, you will learn how to install ``libmongoc``, |
| 12 | +which comes bundled with ``libbson``. |
| 13 | + |
| 14 | +You can install the {+driver-short+} by using |
| 15 | +a package manager, or by installing the libraries from source. Different Linux |
| 16 | +distributions install different versions of the driver when installed with a |
| 17 | +package manager. Because of this, you should check the version your distribution |
| 18 | +includes before installing the driver. |
| 19 | + |
| 20 | +On RedHat Enterprise Linux (RHEL) distributions, you can check the version by |
| 21 | +running the following command in your shell: |
| 22 | + |
| 23 | +.. code-block:: bash |
| 24 | + |
| 25 | + sudo dnf info mongo-c-driver-devel |
| 26 | + |
| 27 | +On Debian-based distributions, you can check the version by running the |
| 28 | +following command in your shell: |
| 29 | + |
| 30 | +.. code-block:: bash |
| 31 | + |
| 32 | + apt-cache policy libmongoc-dev |
| 33 | + |
| 34 | +If the version of the driver that is available is not the version you want, you |
| 35 | +can install the driver from source. |
| 36 | +.. TODO: To learn how to install the driver from source, see the c-install-from-source guide. |
| 37 | + |
| 38 | +To learn how to install the driver by using a package manager, select the tab corresponding to |
| 39 | +your operating system: |
| 40 | + |
| 41 | +.. tabs:: |
| 42 | + |
| 43 | + .. tab:: Linux |
| 44 | + :tabid: install-linux |
| 45 | + |
| 46 | + .. _c-redhat-install: |
| 47 | + |
| 48 | + RedHat Enterprise Linux Distributions |
| 49 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 50 | + |
| 51 | + You can install the driver on RedHat Enterprise Linux (RHEL) |
| 52 | + distributions, version 7 or later, or distributions based on RHEL, |
| 53 | + such as: |
| 54 | + |
| 55 | + - `CentOS <https://www.centos.org/>`__ |
| 56 | + - `Rocky Linux <https://rockylinux.org/>`__ |
| 57 | + - `AlmaLinux <https://almalinux.org/>`__ |
| 58 | + |
| 59 | + Before you install the driver on a RHEL distribution, not including |
| 60 | + Fedora, you must first enable the Extra Packages for Enterprise |
| 61 | + Linux (EPEL) repository. You can enable the EPEL repository by |
| 62 | + installing the ``epel-release`` package, as shown in the following |
| 63 | + example: |
| 64 | + |
| 65 | + .. code-block:: bash |
| 66 | + |
| 67 | + yum install epel-release |
| 68 | + |
| 69 | + Then, you can install the {+driver-short+} |
| 70 | + by using ``yum``. To do so, run the following command in |
| 71 | + your shell: |
| 72 | + |
| 73 | + .. code-block:: bash |
| 74 | + |
| 75 | + yum install mongo-c-driver-devel |
| 76 | + |
| 77 | + .. note:: Developer Packages |
| 78 | + |
| 79 | + The preceding code example installs the developer packages, which |
| 80 | + are required to build applications that use the {+driver-short+}. To |
| 81 | + install only the libraries, without development files, run the |
| 82 | + following command: |
| 83 | + |
| 84 | + .. code-block:: bash |
| 85 | + |
| 86 | + yum install mongo-c-driver |
| 87 | + |
| 88 | + If you are installing on a RHEL distribution that is version 8 or |
| 89 | + later, we recommend running the preceding code examples by using |
| 90 | + ``dnf`` instead of ``yum``. |
| 91 | + |
| 92 | + Fedora |
| 93 | + ~~~~~~ |
| 94 | + |
| 95 | + If you are using Fedora or an enterprise Linux distribution of |
| 96 | + version 8 or later, you can install the driver by using the same |
| 97 | + commands as shown in the :ref:`preceding example <c-redhat-install>` |
| 98 | + and replacing ``yum`` with ``dnf``. |
| 99 | + |
| 100 | + The following example shows how to install the {+driver-short+} in a |
| 101 | + Fedora distribution: |
| 102 | + |
| 103 | + .. code-block:: bash |
| 104 | + |
| 105 | + dnf install mongo-c-driver-devel |
| 106 | + |
| 107 | + Debian-Based Distributions |
| 108 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 109 | + |
| 110 | + In Debian-Based Linux distributions, including Ubuntu and Ubuntu |
| 111 | + derivatives, the driver libraries are available through the Advanced |
| 112 | + Packaging Tool (APT). You can install the driver with APT by running |
| 113 | + the following command in your shell: |
| 114 | + |
| 115 | + .. code-block:: bash |
| 116 | + |
| 117 | + apt install libmongoc-dev |
| 118 | + |
| 119 | + The preceding code example installs the developer packages, which |
| 120 | + are required to build applications that use the {+driver-short+}. To |
| 121 | + install only the libraries, without development files, run the |
| 122 | + following command: |
| 123 | + |
| 124 | + .. code-block:: bash |
| 125 | + |
| 126 | + apt install libmongoc-1.0-0 |
| 127 | + |
| 128 | + .. tab:: Windows |
| 129 | + :tabid: install-windows |
| 130 | + |
| 131 | + For Windows environments, we recommend building the {+driver-short+} |
| 132 | + libraries from source to ensure maximum compatibility with the local |
| 133 | + toolchain. You can automate building from source by using a |
| 134 | + from-source library package management tool, such as |
| 135 | + `vcpkg <https://vcpkg.io>`__. |
| 136 | + |
| 137 | + .. tip:: |
| 138 | + |
| 139 | + To learn how to get started with vcpkg, see the `vcpkg Get Started |
| 140 | + guide <https://learn.microsoft.com/en-us/vcpkg/get_started/overview>`__ |
| 141 | + in the Microsoft documentation. |
| 142 | + |
| 143 | + In `vcpkg manifest mode <https://learn.microsoft.com/en-us/vcpkg/users/manifests>`__, add the |
| 144 | + driver library to your project's ``vcpkg.json`` manifest file, |
| 145 | + as shown in the following example: |
| 146 | + |
| 147 | + .. code-block:: js |
| 148 | + |
| 149 | + { |
| 150 | + // ... |
| 151 | + "dependencies": [ |
| 152 | + // ... |
| 153 | + "mongo-c-driver" |
| 154 | + ] |
| 155 | + } |
| 156 | + |
| 157 | + When you build a CMake project with vcpkg integration and have a |
| 158 | + ``vcpkg.json`` manifest file, vcpkg automatically installs the project's |
| 159 | + dependencies before proceeding with configuration. |
| 160 | + |
| 161 | + If you are using `vcpkg classic mode <https://learn.microsoft.com/en-us/vcpkg/users/classic-mode>`__, |
| 162 | + you can install the driver by running the following command in |
| 163 | + your shell: |
| 164 | + |
| 165 | + .. code-block:: bash |
| 166 | + |
| 167 | + vcpkg install mongo-c-driver |
| 168 | + |
| 169 | + After you install the driver, the standard CMake configuration file |
| 170 | + is available, as well as the generated ``IMPORTED`` targets. You can |
| 171 | + create a ``CMakeLists.txt`` file as shown in the following example: |
| 172 | + |
| 173 | + .. code-block:: cmake |
| 174 | + |
| 175 | + find_package(mongoc-1.0 CONFIG REQUIRED) |
| 176 | + target_link_libraries(my-application |
| 177 | + PRIVATE $<IF:$<TARGET_EXISTS:mongo::mongoc_shared>,mongo::mongoc_shared,mongo::mongoc_static>) |
| 178 | + |
| 179 | + .. note:: |
| 180 | + |
| 181 | + You can use the ``$<IF:$<TARGET_EXISTS...>:...>`` generator |
| 182 | + expression in the preceding example to switch the link type of |
| 183 | + ``libmongoc`` based on the form that is available from the |
| 184 | + ``find_package()`` command. ``libmongoc`` supports building with |
| 185 | + both *dynamic* and *static* library types, but vcpkg |
| 186 | + installs only one type at a time. |
| 187 | + |
| 188 | + To configure the CMake project with vcpkg integration, set the CMake |
| 189 | + toolchain file in the configuration command by running the following |
| 190 | + commands in your shell: |
| 191 | + |
| 192 | + .. code-block:: bash |
| 193 | + |
| 194 | + cmake -S . -B _build -D |
| 195 | + CMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake |
| 196 | + |
| 197 | + .. tab:: MacOS |
| 198 | + :tabid: install-mac |
| 199 | + |
| 200 | + You can download the {+driver-short+} on MacOS by using the `Homebrew |
| 201 | + package manager <https://brew.sh/>`__. To do so, run the following command in |
| 202 | + your shell: |
| 203 | + |
| 204 | + .. code-block:: bash |
| 205 | + |
| 206 | + brew install mongo-c-driver |
| 207 | + |
| 208 | +.. TODO: |
| 209 | + .. To learn how to install the driver libraries from source, see the |
| 210 | + .. :ref:`c-install-from-source`` guide. |
| 211 | + |
| 212 | +After you complete these steps, you have the {+driver-short+} installed |
| 213 | +on your machine. |
| 214 | + |
| 215 | +.. include:: /includes/get-started/troubleshoot.rst |
0 commit comments