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 containing tools and utilities that you can add to your project, and that facilitate the construction of programs and applications.

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

paquete

In addition, the main “advantage” 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.

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”, usually paid

What is a package manager

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

Package managers are fundamental tools in the software development process, especially to not go 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.

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

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

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

Finally, package managers usually have one or several configuration files. It is generally a text file (in simple format, toml, yaml, json…) with a specific name.

Examples of package managers

It’s better to 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 packaje.json

Python uses the “PIP” (pip installs packages) package manager. 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. Instead, 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, making the process of building and linking projects in C++ easier. 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