Ir al contenido principal

Install mongosh in Linux Debian

mongosh, the MongoDB Shell, is a JavaScript and Node.js REPL environment for interacting with MongoDB deployments in Atlas, locally, or on another remote host.

It is a really productive tool that, by the time of writing this article, is not yet included in the Debian distributions.

Does that mean that it cannot be installed on Debian? The response is yes, it can be installed on Debian, since MongoDB publishes the .deb packages for different Debian distribution on its own repository. The steps are described below.

1. Check the Debian distribution name

This section deals with the steps needed to determine the Debian distribution name (wheezy, stretch, jessie, buster, bullseye, bookworm,...) of the system where mongosh is being installed. In case you know it, this step can be omitted.

Install the latest version of lsb-release:

sudo apt-get update
sudo apt-get install lsb-release

Once installed, run the command:

lsb-release -a

2. Import the MongoDB public key used by the package management system

In order to access to the MongoDB Linux repository, you need to authenticate with the MongoDB public GPG key. This section explains how to install it locally.

From a terminal on the Debian system where mongosh must be installed, install gnupg and curl (in case then were not already installed):

sudo apt-get install gnupg curl

Import the MongoDB public GPG key from https://pgp.mongodb.com/server-7.0.asc and store it in the file /usr/share/keyrings/mongodb-server-7.0.gpg by running the following command:

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
   sudo gpg -o \
   /usr/share/keyrings/mongodb-server-7.0.gpg \
   --dearmor

3. Configure the MongoDB repository as .deb packages source

Create a package source list file (/etc/apt/sources.list.d/mongodb-org-7.0.list) using the name of the Debian distribution obtained in the first step:

echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/7.0 main" | \ 
  sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

Note that the previous example creates a source list file for a Debian bullseye distribution (http://repo.mongodb.org/apt/debian bullseye/mongodb-org/7.0 main). In case of installing mongosh on another Debian distribution, the above command must be adapted with the proper distribution name.

4. Install mongosh

Now that the MongoDB repository has been configured as package source and that the public key needed for authenticating is available, mongosh can be installed by running these commands:

sudo apt-get update
sudo apt-get install -y mongodb-mongosh
  

Sources

  • Install MongoDB on Debian
  • Install mongosh on Ubuntu
  • Comentarios

    Entradas populares de este blog

    Linting C# in Visual Studio Code

    Though very usual in programming environments as Javascript/Typescript, linting , or analyzing code for enforcing a set of coding style rules, is not usually present in the .NET based environments. Rule enforcing is really useful when working on team shared codebases in order to keep them coherent, what in last term reduces both development times and coding errors. A linting example Maybe a practical example would be helpful for explaining what  linting  is to the newcomers (feel free to go on if you aren't). Let's imagine you are a new member in a C# development team that has well established set of coding style rules. Instead (or apart) of putting them in a document, they've adopted a tool that checks these rules during the code building process. Your first code is such ambitious as this: namespace HelloWorld {      using System;      public class Program      {           public static void Main(string[] args)           {                Console

    ESlint: Ignore unused underscore variables

    Some naming conventions promote the use of the underscore character (" _ ") for those variables that must be declared but are not being used. One common case is that in which a function signature contains some variables that will not be used, as for instance the Express error handlers: app.use(function(err, req, res, next) { console.error(err.stack); res.status(500).send('Something broke!'); }); In the above example only the arguments err and res are being used, though all four must be defined in the handler signature. Thus, following the naming convention of using underscores for those unused variables, we could recode it as: app.use(function(err, _, res, __) { console.error(err.stack); res.status(500).send('Something broke!'); }); Though it makes the function more readable, it comes with a problem if using ESlint: it will blame by declaring unused variables. error '_' is defined but never used error '__' is define

    Using Bitbucket app passwords with git on MacOS (OSX)

    Learn how Bitbucket passwords are stored by git on MacOS.