What is a package manager and why is it useful?
A package manager is a programming language’s tool to create project environments and easily import external dependencies. You don’t have to reinvent the wheel and are able to make the most of the tools at your disposal. When working on a project or library, you may “package” your project and publish it for others.
You can usually specify dependencies, a package name, author, tags/keywords and version number. All this helps online repositories store your package and allows others to find your project. Furthermore by allowing you to create your own packages, developers are challenged to think about how their package will be used and implemented, in turn producing better and more reusable packages.
Popular package manager overview
Python – Managers: pip / conda, Repository: pypi
Python is an increasingly popular language and is constantly evolving. “pip” allows you to effortlessly add dependencies to your projects for your given python instalments.
A slightly different approach to package management exist in the form of VirtualEnv and Anaconda. Both implement the concept of creating virtual environments for a given project, this environment includes a fresh python installation for a given version along with the ability to install packages specific to that project.
Where the two differ is that VirtualEnv works with essentially a blank slate python installation and uses pip to install dependencies. In contrast, Anaconda has additional dependencies built-in for data-science tasks and does not use pip. ‘conda’, which is a separate package manager with data-science-related packages, is provided with every Anaconda installation. It does however have built-in compatability with pip to allow for adding packages not available in conda.
For the purpose of simplicity, I think using VirtualEnv allows for the cleanest implementation of package management. You can separate out your projects to only include what you need and avoid global installs you might only be using in a single project. Albeit, the only exception to this is if you are only working on data-science tasks and have no need for additional installations.
Java – Managers: Maven and Gradle, Repository: Maven Central
Java has two main options for package management, Maven is the industry standard. Maven Central Repository is an online repository containing a vast array of packages available for use in your projects. In contrast, Gradle is a relatively new package management solutions that has grown rapidly over recent years due to a less-verbose syntax and faster build times. Java is the only one of these examples where you cannot simply add your own packages to the main repository. Approved repository hosting services such as Sonatype Nexus OSS must vet and agree to host your package on their platform.
In terms of choosing one over the other, for existing applications it is likely Maven is already integrated and moving over to Gradle would have considerable overhead. However, Gradle is less verbose, immediately speeds up builds and will likely continue to increase in popularity.
PHP – Manager: Composer, Repository: Packagist
Composer is the package manager for PHP along with Packagist which is the main PHP package repository. Composer challenges PHP’s traditional single-script server usage by allowing package imports. Furthermore, Composer allows imports to be used traditionally from a server endpoint or simply from running scripts via the command line interchangeably.
Like npm, linking GitHub and Packagist allows for seamless deployment to the platform.
Now that I’ve described a bunch of package managers and their corresponding repositories, I would highly suggest experimenting with them. Try creating a project, import some dependencies and use them! You will quickly realise the importance of re-usable packages outside of the built-in scope and see how simply you can make use of them via package management.
Finally, if you feel comfortable using packages and find yourself programming something others might find useful, create your own! Create a library or project and deploy it to the corresponding public repository.