Время на прочтение2 мин
Количество просмотров19K
Коллеги, которые только начали погружение в мир Cloud Native, часто задаются вопросом, как установить необходимое ПО на Windows. Решение уже давно известно — Windows Subsystem for Linux (WSL). Это действительно неплохой вариант для полноценной работы. И не забывайте, что установить все необходимые утилиты очень просто — вам нужен Homebrew. Этот пакетный менеджер уже давно доступен не только для OS X, но и для Linux. Приступим!
Установка Ubuntu 20.04
Заходим в Microsoft Store и устанавливаем Ubuntu 20.04. Может потребоваться удалить старую версию:
CTRL + R -> CMD
#Check installation
C:\Users\suchak>wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-20.04
Legacy (Default)
#Uninstalling older version
C:\Users\suchak>wsl --unregister Legacy
#Check the default installation again
C:\Users\suchak>wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
Устанавливаем терминал для Windows
Iterm2 — великолепный терминал для OS X. Работая в Linux я предпочитаю Tilix. А что же выбрать для работы с Windows? Неплохим решением может быть Terminus, хотя вы можете использовать и Power Shell.
Для установки Terminus загружаем инсталляционный файл для Windows из официального репозитория на GitHub.
Устанавливаем Homebrew
Запускаем терминал Terminus и приступаем к установке. Для работы Homebrew требуется gcc:
sudo apt install gcc
Теперь устанавливаем Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Всё готово!
Установим необходимые программы:
brew install kind kubernetes-cli helm k9s kubectx kubecolor
Теперь мы можем без труда устанавливать дополнительные приложения, работая c Windows, как если бы мы работали с OS X или Linux.
Homebrew is a package manager that makes it easy to install and update applications and utilities on Linux, Mac, and Windows.
You might already know a package manager if you are familiar with Linux. Think of yum, apt, or the modern Flatpak.
With Homebrew you:
- Can install software to your home directory and so does not require sudo
- Install software not packaged by your host distribution
- Install up-to-date versions of software when your host distribution is old
- Use the same package manager to manage your macOS, Linux, and Windows systems
How To Install Homebrew
Installing Homebrew is extremely simple.
On Mac & Linux
If you are using Mac or Linux, open your terminal and use the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
as reported in the official documentation.
Once the installation is completed, you might see something like the following:
I recommend adding Homebrew to your PATH as suggested in the Next steps.
Run each command one by one and, if possible, install build-essential
and gcc
.
Once you are done, run the following command:
brew --version
The outcome should be something like:
Homebrew 3.5.6-66-g43aXXXX
Homebrew/homebrew-core (git revision aa8a2e2b149; last commit 2022-07-29)
You might want to install GitHub Desktop on your Linux OS if you are working on Linux.
Otherwise, that’s it! You are good to go!
On Windows
If you are using Windows, you must take one more step before installing Homebrew.
1. Install Windows Subsystem for Linux (WSL)
According to the Microsoft docs, the “Windows Subsystem for Linux lets developers run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup”.
Follow this guide to install WSL on your Windows.
2. Install Homebrew
Once you have your Windows Subsystem for Linux (WSL) installed, open the terminal and use the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
as reported in the official documentation.
Once the installation is completed, you might see something like the following:
I recommend adding Homebrew to your PATH as suggested in the Next steps.
Run each command one by one and, if possible, install build-essential
and gcc
.
Once you are done, run the following command:
brew --version
The outcome should be something like:
Homebrew 3.5.6-66-g43aXXXX
Homebrew/homebrew-core (git revision aa8a2e2b149; last commit 2022-07-29)
That’s it! You are good to go!
Instructions for a supported install of Homebrew are on the homepage.
The script installs Homebrew to its default, supported, best prefix (/opt/homebrew
for Apple Silicon, /usr/local
for macOS Intel and /home/linuxbrew/.linuxbrew
for Linux) so that you don’t need sudo after Homebrew’s initial installation when you brew install
. This prefix is required for most bottles (binary packages) to be used. It is a careful script; it can be run even if you have stuff installed in the preferred prefix already. It tells you exactly what it will do before it does it too. You have to confirm everything it will do before it starts.
The macOS .pkg
installer also installs Homebrew to its default prefix (/opt/homebrew
for Apple Silicon and /usr/local
for macOS Intel) for the same reasons as above. It’s available on Homebrew/brew’s latest GitHub release. To specify an alternate install user, like in situations where the package is installed at the login window before a user has logged in, write a property list file to /var/tmp/.homebrew_pkg_user.plist
with the value HOMEBREW_PKG_USER
. For example, defaults write /var/tmp/.homebrew_pkg_user HOMEBREW_PKG_USER penny
. The file and user must exist prior to install.
macOS Requirements
- An Apple Silicon CPU or 64-bit Intel CPU 1
- macOS Ventura (13) (or higher) installed on officially supported hardware2
- Command Line Tools (CLT) for Xcode (from
xcode-select --install
or
https://developer.apple.com/download/all/) or
Xcode 3 - The Bourne-again shell for installation (i.e.
bash
) 4
Advanced Configuration
The Homebrew installer offers various advanced configuration settings. Most users can skip this section and instead follow the instructions on the homepage!
Git Remote Mirroring
If you have issues connecting to GitHub.com, you can use Git mirrors for Homebrew’s installation and brew update
by setting HOMEBREW_BREW_GIT_REMOTE
and/or HOMEBREW_CORE_GIT_REMOTE
in your shell environment with this script:
export HOMEBREW_BREW_GIT_REMOTE="..." # put your Git mirror of Homebrew/brew here
export HOMEBREW_CORE_GIT_REMOTE="..." # put your Git mirror of Homebrew/homebrew-core here
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The default Git remote will be used if the corresponding environment variable is unset and works best for most users.
Note: if you set these variables you are granting these repositories the same level of trust you currently grant to Homebrew itself. You should be extremely confident that these repositories will not be compromised.
Default Tap Cloning
You can instruct Homebrew to return to pre-4.0.0 behaviour by cloning the Homebrew/homebrew-core tap during installation by setting the HOMEBREW_NO_INSTALL_FROM_API
environment variable with the following:
export HOMEBREW_NO_INSTALL_FROM_API=1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This will make Homebrew install formulae and casks from the homebrew/core
and homebrew/cask
taps using local checkouts of these repositories instead of Homebrew’s API. Unless you are a Homebrew maintainer or contributor, you should probably not globally enable this setting. It can easily be enabled later after installation should it be necessary.
Unattended installation
If you want a non-interactive run of the Homebrew installer that doesn’t prompt for passwords (e.g. in automation scripts), prepend NONINTERACTIVE=1
to the installation command.
Alternative Installs
Linux or Windows 10 Subsystem for Linux
Check out the Homebrew on Linux installation documentation.
Untar anywhere (unsupported)
Technically, you can just extract (or git clone
) Homebrew wherever you want. However, you shouldn’t install outside the default, supported, best prefix. Many things will need to be built from source outside the default prefix. Building from source is slow, energy-inefficient, buggy and unsupported. The main reason Homebrew just works is because we use bottles (binary packages) and most of these require using the default prefix. If you decide to use another prefix: don’t open any issues, even if you think they are unrelated to your prefix choice. They will be closed without response.
TL;DR: pick another prefix at your peril!
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip-components 1 -C homebrew
or:
git clone https://github.com/Homebrew/brew homebrew
then:
eval "$(homebrew/bin/brew shellenv)"
brew update --force --quiet
chmod -R go-w "$(brew --prefix)/share/zsh"
Make sure you avoid installing into:
- Directories with names that contain spaces. Homebrew itself can handle spaces, but many build scripts cannot.
/tmp
subdirectories because Homebrew gets upset./sw
and/opt/local
because build scripts get confused when Homebrew is there instead of Fink or MacPorts, respectively.
Multiple installations (unsupported)
Create a Homebrew installation wherever you extract the tarball. Whichever brew
command is called is where the packages will be installed. You can use this as you see fit, e.g. to have a system set of libs in the default prefix and tweaked formulae for development in ~/homebrew
.
Post-installation steps
When you install Homebrew, it prints some directions for updating your shell’s config.
If you don’t follow those directions, Homebrew will not work.
You need to update your shell’s config file (which file exactly depends on your shell, for example ~/.bashrc
or ~/.zshrc
) to include this:
eval "$(<Homebrew prefix path>/bin/brew shellenv)"
Replace <Homebrew prefix path>
with the directory where Homebrew is installed on your system.
You can find Homebrew’s default install location in this FAQ entry.
For more insight, re-run the installer or inspect the installer’s source
to see how the installer constructs the path it recommends.
See Tips and Tricks > Loading Homebrew from the same dotfiles on different operating systems
for another way to handle this across multiple operating systems.
Uninstallation
Uninstallation is documented in the FAQ.
1 For 32-bit or PPC support see Tigerbrew.
2 macOS 13 (Ventura) or higher is best and supported, 10.11 (El Capitan) – 12 (Monterey) are unsupported but may work and 10.10 (Yosemite) and older will not run Homebrew at all. For 10.4 (Tiger) – 10.6 (Snow Leopard) see Tigerbrew. Using OpenCore Legacy Patcher is a Tier 2 or Tier 3 configuration depending on CPU generation.
3 You may need to install Xcode, the CLT, or both depending on the formula, to install a bottle (binary package) which is the only supported configuration. Downloading Xcode may require an Apple Developer account on older versions of Mac OS X. Sign up for free at Apple’s website.
4 The one-liner installation method found on brew.sh uses the Bourne-again shell at /bin/bash
. Notably, zsh
, fish
, tcsh
and csh
will not work.
Linux is a part of Windows 10 and it is easily one of the biggest features to have come to Windows since its inception. It’s big for Windows 10, but no previous version of Windows had Linux so it’s a milestone like no other. There are still some limitations that remain but Microsoft has been improving WSL with each major feature update. If you’re using WSL on Windows 10, you may want to, at some point install Homebrew on it.
Homebrew is an essential app on Linux so it stands to reason that you might need it on WSL as well. Here’s how you can install Homebrew on Windows Subsystem for Linux.
Enable WSL & install Linux
Before you can install Homebrew on Windows Subsystem for Linux, you need to enable it and install a Linux OS on Windows 10. You can use any of the Linux operating systems that are available and the commands given below will work. For this post, we’re going with Ubuntu for Windows 10. It was the first ever OS to be supported for Windows 10 and will by far be the best in terms of features and stability.
Open whichever Linux OS you’ve installed on Windows 10 by searching for it in Windows Search or by launching it from the Start Menu.
Run the following command;
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
The command can take anywhere between 10-20 minutes to complete. You will have to enter your Linux password, and confirm the installation of some components during installation.
Once Homebrew has been installed, you will see a message telling you that /home/linuxbrew/.linuxbrew/bin is not in your PATH. This is easily fixed.
Run the following commands, and they will take care of everything.
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv) test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
These commands complete within seconds. Once they’re done, you can start using Homebrew in WSL.
When to use Homebrew?
In WSL, you can install apps from the software center of whichever Linux OS you’re running however, in some cases, the app may not install. In that case, it’s always worth giving Homebrew a try. If there’s an app that you simply cannot install from the software center i.e., it isn’t available there, Homebrew might be the only way to install it.
If you want to uninstall Homebrew, you can try the uninstall command but given this is WSL, it might be better to do a clean install of your Linux OS instead. As we said before, WSL still has some limitations.
Fatima Wahab
Fatima has been writing for AddictiveTips for six years. She began as a junior writer and has been working as the Editor in Chief since 2014.
Fatima gets an adrenaline rush from figuring out how technology works, and how to manipulate it. A well-designed app, something that solves a common everyday problem and looks
Installing homebrew / Linuxbrew on Ubuntu-18.04 wsl for Windows 10
open wsl command line
type —
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
You will need to manually add the directory to your PATH.
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv) test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
If you have the following error:
Error: patchelf must be installed: brew install patchelf Warning: Bottle installation failed: building from source. Error: The following formula patchelf cannot be installed as binary package and must be built from source.
The recommended solution of brew install gcc
may result in the same error.
A fix is to run the following commands to get brew
working properly.
sudo apt-get update sudo apt-get install build-essential
Why did I want to do this?
I’m tired of needing to manually log into github to create a repo, copy the clone url, and making the initial clone to my computer, so that I can start working on a project. It would be so much simpler to just create the repo from the terminal and push up the data as I build…
So this allows me to brew install hub
and remotely create github repos from the terminal
hub create -d "<commit name>"
In my book, that’s a WIN
Links:
- Edward Baeg on Medium
- Hub
- Hub repo
#dsmith73 |
---|