Normally, 0install downloads a feed from the web, selects a version, downloads the archive for that version, and runs it. However, 0install can also be used locally (e.g. to run a program you are currently writing, which hasn't been released yet). There are several reasons why you might want to do this:
- 0install can select and download your program's build or runtime dependencies.
- It provides a cross-platform way to set environment variables and start your program.
- You can use 0release to generate releases automatically.
A simple example¶
Let's say you have a simple Python 2 program,
print "Hello World!"
You could make this runnable by specifying a shebang line. But that wouldn't work on Windows (which doesn't support them). Also, different versions of Linux need different lines (e.g.
#!/usr/bin/python on Debian, but
#!/usr/bin/python2 on Arch).
Instead, we can create a local feed to say how to run it. Create
hello.xml in the same directory:
<?xml version="1.0" ?> <interface xmlns="http://zero-install.sourceforge.net/2004/injector/interface"> <name>Hello</name> <summary>minimal demonstration program</summary> <implementation id="." version="0.1-pre"> <command name='run' path='hello.py'> <runner interface='https://apps.0install.net/python/python.xml'> <version before='3'/> </runner> </command> </implementation> </interface>
id="." says that the implementation of this interface is the directory containing the feed (whereas normally we'd specify a digest and a URL from which to download the archive).
There are two other differences to note: there is no digital signature at the end (we assume that no attacker could intercept the file between your harddisk and you ;-), and the version number ends in a modifier (
-pre in this case), showing that it hasn't been released.
You can now use this feed with the usual 0install commands. For example:
$ 0install run hello.xml Hello World! $ 0install add hello-dev hello.xml $ hello-dev Hello World! $ 0install select hello.xml \- URI: /home/bob/hello/hello.xml Version: 0.1-pre Path: /home/bob/hello \- URI: https://apps.0install.net/python/python.xml Version: 2.7.3 Path: (package:deb:python2.7:2.7.3:x86_64)
This will work on Linux, macOS, Windows, etc.
Some more things you can do with your new local feed:
- Depend on other libraries or tools (see the feed specification for reference).
- Compile source code using 0compile.
- Make a release using 0release.
- Test against different versions of dependencies using 0test.
See the example templates for projects in different languages and using various build systems.