125

Is there a way to install a deb package directly from a URL, using a shell? Something like

dpkg -i http://domain.com/path/to/package.deb

(I know I could use wget and then dpkg, I'm just wondering if there's something that does it already)

Joril
  • 2,424

13 Answers13

81

Edit: I didn't see your previous statement about knowing you could wget so this is a bit awkward... I'll leave this here for anybody who wants to know how to do this. Additionally the previous version of my answer didn't work but this version (at the expense of being somewhat longer) does:

TEMP_DEB="$(mktemp)" &&
wget -O "$TEMP_DEB" 'http://path.to/my.deb' &&
sudo dpkg -i "$TEMP_DEB"
rm -f "$TEMP_DEB"

You just need to alter the URL at the beginning. This could be aliased or written as a bash function.

I realise there are technical and security issues surrounding this (you don't get automatic updates, can the source be trusted, etc), but on a purely can-I-do-it basis, this might work.

David Foerster
  • 36,890
  • 56
  • 97
  • 151
Oli
  • 299,380
41

It is not possible without creating a temporary file. Normally you would do this like

### Does not work
wget --quiet --output-document=- http://example.com/path/to/package.deb | dpkg --install -

or maybe

### Does not work
dpkg --install <(wget --quiet --output-document=- http://example.com/path/to/package.deb)

but dpkg uses mmap to access the file so neither works. There is a bug report about this: #367297

rvernica
  • 103
Tgr
  • 663
12

If you have (or install) Ansible:

ansible -m apt -a deb=http://domain.com/path/to/package.deb localhost
Diablotin
  • 121
12

You may try with curl.

To download the file into the current folder and install from the local file:

curl -sLO https://apt.puppetlabs.com/puppetlabs-release-precise.deb && sudo dpkg -i puppetlabs-release-precise.deb

or download into /var/cache/apt/archives/ and install from there:

curl -sL -o/var/cache/apt/archives/puppetlabs-release-precise.deb https://apt.puppetlabs.com/puppetlabs-release-precise.deb && sudo dpkg -i /var/cache/apt/archives/puppetlabs-release-precise.deb
kenorb
  • 10,944
9

The quickest method is like this. Click to start installing shutter .

URLs used for clicking on the name:

http://packages.ubuntu.com/shutter

... and for the click on the icon:

http://apt.ubuntu.com/p/shutter

And yes you need Ubuntu Software Center to finish the installation of a .DEB. Otherwise you will have to execute the installation from Nautilus or command line.

Complete text used for this is for Ask Ubuntu only so you need to reformat this into an anchor:

[shutter](http://packages.ubuntu.com/shutter) [![Install shutter]
(https://i.sstatic.net/HjNGK.png)](http://apt.ubuntu.com/p/shutter)

More info can be found on the apturl wiki page:

  1. 1 Package:

    a href="apt:package"
    
  2. Bundling several packages:

    a href="apt:package1,package2,package3"
    
  3. Enabling repositories:

    apturl apt:freevial?section=universe
    

So if the software is not in a default enabled repository you should add a 'section=' to it. Otherwise you can not use this method and need the user to download it and install themselves.

Kulfy
  • 18,154
Rinzwind
  • 309,379
4

I actually have a script that does something similar:

Just copy and paste this script into ~/bin (create this folder if it doesn't exist):

#!/bin/bash
# ~/bin/dpkg
COUNT=0
for i in $@; do
        echo $i | grep http 2>&1 > /dev/null
        if [ $? == 0 ]; then
                URL="$URL $i"
                continue
        fi
        PASSTODPKG="$PASSTODPKG $i"
done

#Remove beginning and trailing space
URL=$(echo $URL | sed -e 's/^ //g' -e 's/ $//g')

if [ ! -z $URL ]; then
        mkdir /tmp/debs
        cd /tmp/debs
        for i in $URL; do
                wget "$i"
        done
        dpkg $PASSTODPKG /tmp/debs/*.deb
else
        dpkg $PASSTODPKG
fi

Then add this to the last line in ~/.bashrc

PATH="~/bin:$PATH"

The script is just a wrapper for dpkg. The line in the ~/.bashrc file tells bash that whenever you type dpkg, it will run ~/bin/dpkg (the script), rather than /usr/bin/dpkg.

The script will just pass the arguments to dpkg if there's no URL's given. The script also supports multiple URL's. Here are some examples that will work:

sudo dpkg -i http://www.example.com/file1.deb
sudo dpkg -i http://www.example.com/file1.deb http://www.example.com/file2.deb
sudo dpkg -i http://www.example.com/file1.deb existing.deb http://www.example.com/file2.deb
sudo dpkg -i existing.deb
Melebius
  • 11,750
3

lynx can call dpkg (or the Software Center, if a display is available) and offer to install a downloaded package for you. For example, using:

lynx http://archive.ubuntu.com/ubuntu/pool/main/z/zsh/

And downloading one of the .deb files, the following prompt is shown:

Info for debian package '/tmp/user/1000/L11127-6774TMP.udeb':
 new debian package, version 2.0.
 size 2545218 bytes: control archive=5830 bytes.
     857 bytes,    21 lines      control              
   14682 bytes,   169 lines      md5sums              
     225 bytes,    20 lines   *  postinst             #!/bin/sh
 Package: zsh-doc
 Source: zsh
 Version: 5.1.1-1ubuntu1
 Architecture: all
 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
 Installed-Size: 5291
 Depends: zsh-common (= 5.1.1-1ubuntu1)
 Section: doc
 Priority: optional
 Homepage: http://www.zsh.org/
 Description: zsh documentation - info/HTML format
  Zsh is a UNIX command interpreter (shell) usable as an
  interactive login shell and as a shell script command
  processor. Of the standard shells, zsh most closely resembles
  ksh but includes many enhancements. Zsh has command-line editing,
  built-in spelling correction, programmable command completion,
  shell functions (with autoloading), a history mechanism, and a
  host of other features.
  .
  This contains the documentation in GNU info and HTML formats.
 Original-Maintainer: Debian Zsh Maintainers <pkg-zsh-devel@lists.alioth.debian.org>

Do you wish to:
 - I)nstall the package now,
 - S)ave it to a file, or
 - Q)uit now
Your choice (I/S/Q)? I
Installation of Debian packages needs to be done as root.
Enter command used to become root (default=sudo): 

Installing package...
[sudo] password for bro3886: 
(Reading database ... 756955 files and directories currently installed.)
Preparing to unpack .../user/1000/L11127-6774TMP.udeb ...
Unpacking zsh-doc (5.1.1-1ubuntu1) over (5.0.5-4ubuntu1~ubuntu14.04.1) ...
dpkg: dependency problems prevent configuration of zsh-doc:
 zsh-doc depends on zsh-common (= 5.1.1-1ubuntu1); however:
  Version of zsh-common on system is 5.0.5-4ubuntu1~ubuntu14.04.1.

dpkg: error processing package zsh-doc (--install):
 dependency problems - leaving unconfigured
Processing triggers for doc-base (0.10.5) ...
Processing 1 changed doc-base file...
Processing triggers for install-info (5.2.0.dfsg.1-2) ...
Errors were encountered while processing:
 zsh-doc

Done.  Press <return> to continue: 

(Maybe I shouldn't try to install random packages off the internet.)

muru
  • 207,228
2

This one-liner based on an SO answer worked for me on Ubuntu 15.04 to identify the latest atom release on github for my environment (64-bit Ubuntu) and then install it:

sudo dpkg -i $(curl -w "%{filename_effective}" -LO $(curl -s https://api.github.com/repos/atom/atom/releases | grep browser_download_url | grep '64[.]deb' | head -n 1 | cut -d '"' -f 4))

If you do this in a tmp dir, the deb file will be cleaned up whenever you empty your tmp folder. Otherwise you can manually delete the deb package if you need the disk space.

hobs
  • 562
1

One line solution to download, install and delete package after install:

deb=$(curl -w "%{filename_effective}" -LO https://nginx.org/packages/ubuntu/pool/nginx/n/nginx/nginx_1.20.0-1~focal_amd64.deb) && dpkg -i $deb && rm $deb && unset deb
1

I know that it's been a while since this question was answered/posted, but here's my humble contribution:

#!/bin/bash
dir="/tmp/dpkg-get"
url="$1"
file="${url##*/}"

if [ "$EUID" -ne 0 ]
then
echo "Please run as root"
exit
fi

[ -d $dir ] || mkdir $dir
wget -q --show-progress -O "$dir/$file" $url && \
dpkg -i "$dir/$file"

How to install dpkg-get from Pastebin with a single command:

sudo bash -c "wget http://pastebin.com/raw/GWu7qLwK -O- | tr -d '\r' > /usr/local/bin/dpkg-get && \
chmod a+x /usr/local/bin/dpkg-get"

How to use it (for example to install PowerShell 6 alpha):

sudo dpkg-get https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.10/powershell_6.0.0-alpha.10-1ubuntu1.16.04.1_amd64.deb

And that's all.

I know it's not perfect, but it's simple and it works.

Remember to be careful with what you install and from where you download it.

TheOdd
  • 3,012
ruverav
  • 11
  • 1
0

I am just wrapped Oli's answer into a bash function that can be added to your .<shell>rc file:

function dpkg_r() {
  local tmp_deb="$(mktemp)"
  local src_url=$1
  local args=${@:2}

  wget -O $tmp_deb $src_url &&
  sudo dpkg -i $tmp_deb $args &&
  { rm -f $tmp_deb; true; } || # commands above succeeded, remove tmp file
  { rm -f $tmp_deb; false; }   # commands above failed, remove tmp file anyway
}

Name it as you want. I named it as dpkg_r where r stands for remote there

Hirurg103
  • 205
0

This command wait for a single URL input (three clicks to select all):

TMP_DEB="$(mktemp)" && read -p "Enter the URL of the .deb file: " FILE_URL && wget -O "$TMP_DEB" "$FILE_URL" && sudo dpkg -i "$TMP_DEB" ; rm -f "$TEMP_DEB" ; unset TMP_DEB FILE_URL

This is my version of dpkgi (dpkg-installer) script (remote and locally) based on other answers:

#!/bin/bash
# Script by Breno Maia (bremaya) <https://www.github.com/bremaya> <bremaya@gmail.com>

Check if the user is root

if [ "$(id -u)" != "0" ]; then echo "dpkg: error: the requested operation requires superuser privileges" >&2 exit 1 fi

URL="" PASSTODPKG=()

cleanup() { rm -rf "$TMPDIR" # Remove the entire temporary directory }

TMPDIR=$(mktemp -d) # Create a unique temporary directory

for i in "$@"; do if [[ "$i" == http* ]]; then URL="$URL $i" else PASSTODPKG+=( "$i") fi done

Remove spaces at the beginning and end of the URL variable

URL=$(echo "$URL" | sed -e 's/^ //' -e 's/ $//')

if [ -n "$URL" ]; then cd "$TMPDIR" for i in $URL; do wget -P "$TMPDIR" "$i" done fi

if [ ${#PASSTODPKG[@]} -gt 0 ]; then dpkg -i "${PASSTODPKG[@]}" fi

if [ -n "$URL" ]; then cd "$TMPDIR" dpkg -i ./*.deb cleanup fi

Function version:

# Add this function to your .bashrc file to install local and remote packages

dpkgi() {

Check if the user is root

if [ "$(id -u)" != "0" ]; then echo "dpkg: error: the requested operation requires superuser privileges" >&2 return 1 fi

URL="" PASSTODPKG=()

cleanup() { rm -rf "$TMPDIR" # Remove the entire temporary directory }

TMPDIR=$(mktemp -d) # Create a unique temporary directory

for i in "$@"; do if [[ "$i" == http* ]]; then URL="$URL $i" else PASSTODPKG+=( "$i") fi done

Remove spaces at the beginning and end of the URL variable

URL=$(echo "$URL" | sed -e 's/^ //' -e 's/ $//')

if [ -n "$URL" ]; then cd "$TMPDIR" for i in $URL; do wget -P "$TMPDIR" "$i" done fi

if [ ${#PASSTODPKG[@]} -gt 0 ]; then dpkg -i "${PASSTODPKG[@]}" fi

if [ -n "$URL" ]; then cd "$TMPDIR" dpkg -i ./*.deb cleanup fi }

0

You can append it to /etc/bash.bashrc as it follows (it's an upgrade from Chen's script):

'dpkg-url'() {

COUNT=0

for package in "${urls[@]}"; do if [[ $package = http ]]; then urls+=("$package") fi

dpkg_url=&quot;$dpkg_url &quot;$package&quot;&quot;

done

Remove beginning and trailing spaces

url=$(echo "$url" | sed -e 's/^ //g' -e 's/ $//g')

if [[ ! -z "$url" ]]; then directory=$(mktemp -d); trap 'rm -rf "$directory"' EXIT

cd &quot;$directory&quot; || exit
    for package in &quot;$url&quot;; do
        wget &quot;&quot;$package&quot;&quot;
    done
dpkg -i $dpkg_url &quot;$directory&quot;/*.deb

else dpkg -i $dpkg_url fi }

Though I do not see why I get this error when calling it as it follows:

dpkg-url -i http://downloads.sourceforge.net/ldview/ldview-4.2-beta1.x64.deb
dpkg: error: need an action option

Type dpkg --help for help about installing and deinstalling packages [*]; Use dselect' oraptitude' for user-friendly package management; Type dpkg -Dhelp for a list of dpkg debug flag values; Type dpkg --force-help for a list of forcing options; Type dpkg-deb --help for help about manipulating *.deb files;

Options marked [*] produce a lot of output - pipe it through less' ormore' !