BD
Buwaneka De SilvaAgile Delivery Leader
← Back to Insights
yumhomebrewchocolatey

My Experience with Package & Dependency Managers

April 15, 2019·8 min read

Have you seen people use apt-get to install packages on Linux distributions or how people just type commands into their terminal and get everything done? This article covers the approach and my experience with each tool.

Package managers overview

Source: https://devrant.com/rants/791178/rant

If you have worked with a Unix-based distribution or would like to learn how to do so as a developer, you are in the right place.

What is a package?

Packages were invented to combat this complexity. Packages collect multiple data files together into a single archive file for easier portability and storage, or simply compress files to reduce storage space. The binaries included in a package are precompiled with the sane defaults the developer has chosen. Packages also contain metadata, such as the software's name, a description of its purpose, a version number, and a list of dependencies necessary for the software to run properly.

What is a dependency?

A program may require one or more other programs to run (the "dependencies"). The dependencies can be recursive with potentially very deep relationships. Sometimes the dependency is only for testing or "building/compiling" the program, i.e. a development or "dev" dependency. Sometimes it is needed to run the program; other times it can be optional to provide extra features.

Homebrew

I became a Mac OS user in 2017. To state the obvious, macOS is a Unix-based operating system, so some of the core features you find on Linux distributions are available here too. To understand the difference between macOS and Linux, follow this link. As I worked across multiple programming languages, I found myself spending too much time installing packages, so I started using shell scripting and eventually discovered Homebrew. This made my life much easier: I could set up environments and install nearly anything I needed for my projects.

To install it, copy and paste the following command into your terminal:

`bash

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

`

As for security implications, yes, there are some alarming vulnerabilities. I suggest you install Homebrew in a location other than /usr/local/bin, ideally within your home folder.

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 58 thousand libraries and is used in over 3 million apps.

When I first started with Swift, I ran into a few problems implementing OAuth, live streaming from a device, and similar tasks. Like many developers, my first instinct was to code the solution from scratch. Later, when I ran into the same problems many developers had before me, I started using the official SDKs provided via CocoaPods. This was much easier than building the modules from scratch. Just make sure to validate things before jumping to conclusions.

To install it, copy and paste the following into your terminal:

`bash

sudo gem install cocoapods

`

Like all package managers, CocoaPods also has vulnerabilities. To safeguard apps or users, I would suggest something like a blacklist. Given that the App Store may reject applications, this is a sensible consideration.

Chocolatey

The sane way to manage software on Windows.

Switching back and forth between Linux distributions, macOS, and Microsoft Windows is like walking on water. It is difficult because many of the tools you use in the terminal may not be available in Command Prompt or PowerShell. The solution is Chocolatey. I have been using it for a few years and, to my understanding, it is a great tool for people like myself who work across different environments.

To install it, copy and paste the following into your Command Prompt:

`powershell

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

`

Chocolatey has its own risks, as many packages require elevated privileges. This concerns me, and it may very well be related to your UAC settings.

Anaconda

You’re probably thinking about snakes.

The open-source Anaconda Distribution is the easiest way to perform Python/R data science and machine learning on Linux, Windows, and macOS.

Yes, it’s a package manager for Python and R, and it’s quite popular because of Python. I use it mostly for Python-related projects, but it also works for the other language families mentioned above.

To install it, copy and paste the following into your terminal or command prompt:

Terminal

`bash

sudo apt-get update | brew update

sudo apt-get install python3.6 | brew install python

cd somewhere

curl -O https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh

bash Anaconda3-5.2.0-Linux-x86_64.sh

`

Note: You might have to set the $PATH.

Windows

`powershell

choco install python --version 3.6.X

choco install anaconda3

`

Note: You might have to set the $PATH. Replace X with the desired version.

Composer

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage the installation and updates for you.

During my sophomore year, I had a final software project with a deadline of two and a half weeks. I had to come up with an idea, conduct a survey, implement an MVP, and present it to an academic panel. It was a mammoth task, and most would say it was impossible. I had a conversation with a few friends and came up with a localized solution tailored to the Sri Lankan market. The baseline idea was related to e-commerce. I wrote the project from scratch using the Slim framework. At the time, I had no idea that PHP also had its own dependency manager. After learning about Slim, I figured it out and delivered the solution on time.

Composer was vulnerable at one point; I remember someone reminding me that it had a 0-day security vulnerability, although it has since been fixed. If you are working heavily with PHP, I recommend using a dependency manager like Composer.

To install it, copy and paste the following into your terminal or command prompt:

Terminal

`bash

#!/bin/sh

EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]

then

>&2 echo 'ERROR: Invalid installer signature'

rm composer-setup.php

exit 1

fi

php composer-setup.php --quiet

RESULT=$?

rm composer-setup.php

exit $RESULT

`

Command Prompt

`powershell

choco install php

choco install composer

`

NPM

CLI for managing your Node modules (packages).

NPM is something I use on a day-to-day basis. Most JavaScript and TypeScript projects require it. I used NPM extensively for Node-related projects, but I found there was a much faster workaround for package management.

To install it, copy and paste the following into your terminal or command prompt:

Terminal

`bash

sudo apt-get nodejs | brew install node

`

Manual installation

`bash

curl -L https://www.npmjs.com/install.sh | sh

`

Command Prompt

`powershell

choco install nodejs.install

`

Ruby Gems

RubyGems is a package manager for the Ruby programming language. It provides a standard format for distributing Ruby programs and libraries, a tool designed to easily manage the installation of gems, and a server for distributing them.

I haven’t had a lot of experience with it, but I started using Ruby when I initially put out my Jekyll site on GitHub in 2016. In general, the Ruby version would not work on Windows without some hassle. Moving to macOS later, I needed Gems to install most of my tools, and it proved itself a viable package manager. For best security practices, follow https://guides.rubygems.org/security/.

To install it, copy and paste the following into your terminal or command prompt:

  • macOS and Linux distributions generally come with RubyGems pre-configured, so reinstallation is not required.

Command Prompt

`powershell

choco install ruby

`

NuGet

NuGet is the package manager for .NET.

If you’re a developer working with .NET, you should probably know this package manager. For most .NET projects, Visual Studio automatically installs the required packages, although this can also be done manually with the NuGet package manager. From my personal experience, the NuGet library has some of the most vulnerable packages to date.

To install it, copy and paste the following into your terminal or command prompt:

Terminal

`bash

sudo apt install nuget | brew install nuget

`

Windows

Install Visual Studio.

Yum

Yum is an automatic updater and package installer/remover for RPM systems. It automatically computes dependencies and figures out what things should occur to install packages.

If you’ve worked with Red Hat or any other RPM-based systems, this would be the tool to manage packages. I remember the sweet memories of working with Red Hat on enterprise-level projects where packages could not be installed directly because of manual firewall restrictions. My team and I had to look for alternative package managers to ensure the requirements of our development teams were met. This package manager is available on most RPM systems, so it usually would not require reinstallation.

← Back to all insights