Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing libraries with leiningen without creating project

I am learning Clojure and coming from a Ruby background.

I am looking for something analogous to gem install <library>. The various incantations of lein install do not seem to fit this bill.

Is there a way to simply install a library locally so that it can be referenced in the REPL without the need to create a project?

like image 495
mydoghasworms Avatar asked May 06 '13 07:05

mydoghasworms


4 Answers

Seems like, you want to install a library with lein. Here is the plugin, install it and use like

 lein localrepo install <filename> <[groupId/]artifactId> <version>
like image 85
Abimaran Kugathasan Avatar answered Oct 23 '22 15:10

Abimaran Kugathasan


If your aim is merely to load libraries in the REPL consider using alembic. It loads dynamically classpaths, resolve dependencies and automatically pulls libraries from the repositories.

Here is a use case:

(require 'alembic.still)
(alembic.still/distill '[enlive "1.1.1"])

It simply requires you to add the following entry to your .lein/project.clj:

{:dev {:dependencies [[alembic "0.1.1"]]}}

See this answer.

like image 23
i-blis Avatar answered Oct 23 '22 15:10

i-blis


Java and thus clojure do not generally have the the idea of globally installed libraries. You should always be creating a classpath with the minimal set of dependencies. You need somehow to specify and manage this classpath and the easiest way to do this is with leiningen, which requires a project.

leiningen automates the process of retrieving the remote libraries and placing them in your local repository which is somewhat analogous to gem install, but these libraries do not become automatically available to a REPL.

The easiest way to have a set of libraries always available is to have a 'scratch' project which you use for REPL experiments before starting a new project. It's not too much of an overhead.

like image 44
sw1nn Avatar answered Oct 23 '22 16:10

sw1nn


In lein 2 you can update profiles.clj with package you want to install:

~\user\.lein\profiles.clj

With the first run of any project with lein, the local repo will be updated with what was incereased in profiles.clj.

Sometimes I just run lein deps without being in a project folder, this will update the local repo for you.

This way you can add any library to your project.clj or call it from repl and it will be extracted from local repo.

like image 24
Samir Avatar answered Oct 23 '22 16:10

Samir