Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install homebrew on Ubuntu inside Docker container

When I try to install homebrew on Ubuntu 18.04

# Dockerfile
FROM ubuntu:18.04

RUN apt-get update && apt-get install build-essential curl file git -y
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

getting errors:

==> Add Ruby to your PATH by running: PATH=/root/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin:$PATH Don't run this as root!

like image 742
Vadim Avatar asked Oct 08 '19 19:10

Vadim


People also ask

How to know if homebrew is correctly installed on Ubuntu?

To know if Homebrew is correctly installed, we can install the test package called hello. Updating Homebrew... 1.- Install homebrew on Ubuntu / Debian Hello, world! With Homebrew you can install many useful programs, to have a complete list run: And you’ll see a long list. 3.- Search for programs to install using Homebrew

How to install packages in Ubuntu Docker container?

Step 1: Open the terminal of your local system and run the Ubuntu Docker Image from the Docker Registry. If your system has no previous pulls, it will start pulling from the registry. Step 2: Now, you have opened the bash of your Ubuntu Docker Container. To install any packages, you first need to update the OS.

How to install Firefox and Vim inside a docker container?

1 Open the terminal of your local system and run the Ubuntu Docker Image from the Docker Registry. ... 2 Now, you have opened the bash of your Ubuntu Docker Container. To install any packages, you first need to update the OS. ... 3 After you have updated the Docker Container, you can now install the Firefox and Vim packages inside it.

Does homebrew need Sudo on Linux?

However, it also has a version for Linux easy to install and use. Homebrew installs the programs in /usr/local and then makes a symbolic link to the binary folder. This means that it does not require sudo and does not affect the system.


2 Answers

Is there a reason you can't use the official image (docker pull linuxbrew/linuxbrew)? It is based on Ubuntu 16.04 / Xenial.

If you must use Bionic (18.04), the correct way to install homebrew will be to follow the steps in the official Dockerfile.

But to get your Dockerfile working, you need to install ruby, create a non-root user and execute the installation script as that user. Like so,

FROM ubuntu:18.04

RUN apt-get update && \
    apt-get install build-essential curl file git ruby-full locales --no-install-recommends -y && \
    rm -rf /var/lib/apt/lists/*

RUN localedef -i en_US -f UTF-8 en_US.UTF-8

RUN useradd -m -s /bin/bash linuxbrew && \
    echo 'linuxbrew ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers

USER linuxbrew
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

USER root
ENV PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}"

PS: I have added --no-install-recommends to ignore optional dependencies and rm -rf /var/lib/apt/lists/* to remove apt-get leftovers thus reducing the image size. Also, locales is added to install UTF-8 or brew will throw a warning when you run the command.

like image 184
Jay Avatar answered Sep 20 '22 18:09

Jay


The new correct way is:

RUN apt-get update && \
    apt-get install -y -q --allow-unauthenticated \
    git \
    sudo
RUN useradd -m -s /bin/zsh linuxbrew && \
    usermod -aG sudo linuxbrew &&  \
    mkdir -p /home/linuxbrew/.linuxbrew && \
    chown -R linuxbrew: /home/linuxbrew/.linuxbrew
USER linuxbrew
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
like image 28
Gabriel Avatar answered Sep 22 '22 18:09

Gabriel