Language: EN

programacion-gestores-paquetes

What are packages and package managers

A package is an organized set of files and directories that groups source code, resources, and metadata related to a specific functionality.

In simpler terms, we could consider them as boxes that contain tools and utilities that you can add to your project, making it easier to build programs and applications.

Within a package, it is common to find one or more libraries. The difference from a library is that they come “packaged” (hence the name) to make it simpler for you to include them in your work.

paquete

A package is a “box” with many things inside

Like libraries, packages can be:

  • Internal, created by you or a coworker
  • Open Source, open source and maintained by the community
  • Proprietary or "third-party", generally paid

Furthermore, the main “grace” of packages is that they include additional information in the form of metadata.

This metadata can include the title, the author’s name, and especially important, information about the version and its dependencies (also with their versions). This facilitates version management, which we already saw could become a real nightmare.

What is a package manager

Packages are added to your project through a package manager. This is a significant difference from a library (which you simply download and plug into your project).

Package managers are essential tools in the software development process, especially to avoid going crazy with versions and dependencies.

The main function of a package manager is to facilitate the installation, updating, configuration, and removal of packages and their dependencies in an automated way.

Package managers also handle dependency resolution. This means that if a package depends on other packages to function correctly, the package manager will automatically download and install the appropriate versions of those dependencies.

Moreover, it is common to have public online repositories, where the versions of the available packages and their dependencies are stored this way, adding a library to your program is even simpler).

Packages and package managers go hand in hand. Each package manager uses its own type of packages. Moreover, they are specific to each programming language.

Most programming languages, such as C#, Python, Java, or JavaScript or C++, for example, have one or more package formats and package managers. In many cases, they come included with the development environment or the language itself.

Finally, package managers often have one or more configuration files. Generally, it is a text file (in simple format, toml, yaml, json…) that has a specific name.

Example of package managers

Let’s see it with some examples.

Node.js uses “NPM” (Node Package Manager) as its default package manager. To add, update, or remove packages, developers can use commands like:

npm install package_name
npm install package_name@version
npm uninstall package_name

In this case, the configuration file is in package.json

Python uses the package manager “PIP” (pip installs packages). With a simple command line, developers can install, update, or remove packages. For example:

pip install package_name
pip install package_name==version
pip uninstall package_name

The configuration file is usually called requirements.txt

C# uses “NuGet” as its standard package manager. NuGet is a command-line tool and an extension for Visual Studio that allows developers to easily add, remove, and update packages in C# and .NET projects. For example:

nuget install PackageName
nuget install PackageName -Version Version
nuget uninstall PackageName

In the past, C# used a “packages.config” file to manage dependencies in older projects, but with the introduction of the PackageReference approach, dependency management has become simpler and more efficient. Now, dependencies are added directly to the .csproj file.

In C++, “Conan” has become a popular package management tool. Conan allows developers to easily manage libraries and their dependencies, facilitating the process of building and linking projects in C++. Usage examples:

conan install PackageName/Version
conan install PackageName/Version@user/channel
conan remove PackageName/Version

The configuration file is usually called conanfile.txt or conanfile.py