Global library install in scala

I’m new to scala. I come from a python and node js background where you can have libraries installed globally. I don’t find any option like the above in scala. Why there isn’t any option to install libraries in scala globally? I’ve searched the same and didn’t arrive at any answer.

Assuming we’re talking about running on the JVM, really this shouldn’t be a
concern specific to Scala, it should be general for the JVM. That said,
there is Conscript:

Anyway, technically you should ask why there isn’t an option to install a
library locally. :wink: The maven or ivy cache is global, unlike the
default in node. (Well, user-global.) I think since maven is more robust,
there’s no danger to having a shared cache and so there’s no reason not to
use one.

But really the point is not about location, but about installing
something as a binary you can run, whether locally or globally. Unlike
python, jar files usually don’t start with a shebang (although it’s
possible – the zip format doesn’t care what’s at the beginning of the
file), so either you have a more tedious command to type (java -jar …),
or you have done extra work to do (like having a wrapper script, which
maven isn’t designed for).

Another route is to use coursier’s launch command:

I built a branch to base all personal sbt builds on, my preferred ad hoc solution to the “new project” problem, and accidentally found it made a sane way to get a quick throwaway environment—whenever I need a fresh one, I just branch it. I add libraries I’m interested in playing with to the sbt build, and all the usual sbt stuff for working with a project works just as well for throwaway experiments, too.

All of my articles on Typelevel and Failex that don’t have their own dedicated repos are worked out and tested in throwaway branches based on this branch.

To be clear, I’m not suggesting that you should use my branch. The nice thing about this workflow is that it’s easy to put together a quick repo—for “globally installed libraries” all you need is a libraryDependencies list and scalaVersion setting in build.sbt, and a one-line project/—and you can use sbt to get a REPL, drive your IDE, compile files with your chosen libraries, &c. It is far more lightweight than it sounds to use a build tool for all your Scala experiments.

This more or less conforms to @tpolecat’s suggestions for getting started with Scala. It’s a little out-of-date but still the best way to get started—fast to get started, scales through years of Scala experience.

Since people are still linking to this, I just submitted this pull request to bring it up to date:

Note also that there is an open pull request to replace the getting started page at with something more sbt-centric, like Rob’s post. The PR is here: . Community help getting this across the finish line would be extremely welcome.

1 Like