Bat: how to install on CentOS 7?

Created on 29 Sep 2018  路  13Comments  路  Source: sharkdp/bat

question

Most helpful comment

@sharkdp THANKS A LOT! 馃槂

According to what you said, I installed it on CentOS 7 like this.

Download bat-vX.Y.Z-x86_64-unknown-linux-musl.tar.gz,

wget -O bat.zip https://github.com/sharkdp/bat/releases/download/v0.7.1/bat-v0.7.1-x86_64-unknown-linux-musl.tar.gz

tar -xvzf bat.zip -C /usr/local

cd /usr/local && mv bat-v0.7.1-x86_64-unknown-linux-musl bat

cd ~

add alias to ~/.zshrc,

alias bat="/usr/local/bat/bat"

and then I can use bat command anywhere!

All 13 comments

We provide binary releases for every major platform: https://github.com/sharkdp/bat/releases

For CentOS, you probably need the bat-vX.Y.Z-x86_64-unknown-linux-musl.tar.gz tarballs to avoid problems with glibc (see #46)

We provide binary releases for every major platform: https://github.com/sharkdp/bat/releases

I don't see a rpm package, so you don't provide a release for every major platform....

I would like to install it on Fedora.

Mebus

@Mebus With platform, I mean CPU architecture and operating system.

Packaging for different distributions is an entirely different story and there are lots of tickets for this already (see e.g. #317).

@sharkdp THANKS A LOT! 馃槂

According to what you said, I installed it on CentOS 7 like this.

Download bat-vX.Y.Z-x86_64-unknown-linux-musl.tar.gz,

wget -O bat.zip https://github.com/sharkdp/bat/releases/download/v0.7.1/bat-v0.7.1-x86_64-unknown-linux-musl.tar.gz

tar -xvzf bat.zip -C /usr/local

cd /usr/local && mv bat-v0.7.1-x86_64-unknown-linux-musl bat

cd ~

add alias to ~/.zshrc,

alias bat="/usr/local/bat/bat"

and then I can use bat command anywhere!

@sharkdp THANKS A LOT! smiley

According to what you said, I installed it on CentOS 7 like this.

Download bat-vX.Y.Z-x86_64-unknown-linux-musl.tar.gz,

wget -O bat.zip https://github.com/sharkdp/bat/releases/download/v0.7.1/bat-v0.7.1-x86_64-unknown-linux-musl.tar.gz

tar -xvzf bat.zip -C /usr/local

cd /usr/local && mv bat-v0.7.1-x86_64-unknown-linux-musl bat

cd ~

add alias to ~/.zshrc,

alias bat="/usr/local/bat/bat"

and then I can use bat command anywhere!

On CentOS 7 I followed you installation instructions but when I run bat I get this error:
zsh: exec format error: /usr/local/bat/bat

How I "installed" bat:

wget -O bat.zip https://github.com/sharkdp/bat/releases/download/v0.8.0/bat-v0.8.0-aarch64-unknown-linux-gnu.tar.gz
tar -xvzf bat.zip -C /usr/local
mv /usr/local/bat-v0.8.0-aarch64-unknown-linux-gnu /usr/local/bat
alias bat='/usr/local/bat/bat'

What am I doing wrong?

Thanks in advance!

@mlopezcoria Are you on an ARM system with aarch64 architecture? If not, please make sure that you use the x86_64 musl version.

Of course!
Sorry for the dumb question. The correct steps would be:

wget -O bat.zip https://github.com/sharkdp/bat/releases/download/v0.8.0/bat-v0.8.0-x86_64-unknown-linux-musl.tar.gz
tar -xvzf bat.zip -C /usr/local
mv /usr/local/bat-v0.8.0-x86_64-unknown-linux-musl /usr/local/bat
alias bat='/usr/local/bat/bat'

Now it works like a charm!
Thank you @sharkdp

wget https://github.com/sharkdp/bat/releases/download/v0.7.1/bat-v0.7.1-x86_64-unknown-linux-musl.tar.gz -O - |tar -xvzf - -C /usr/local/bin && mv /usr/local/bin/bat-v0.7.1-x86_64-unknown-linux-musl/bat /usr/local/bin/bat

I write playbook for RHEL-based distributions:

- name: get bat latest version
  block:
    - shell: curl --silent "https://api.github.com/repos/sharkdp/bat/releases/latest" | grep -Po '"tag_name"':' "\K.*?(?=")' warn=false
      register: latest_release
    - get_url:
        url: https://github.com/sharkdp/bat/releases/download/{{latest_release.stdout}}/bat-{{latest_release.stdout}}-x86_64-unknown-linux-musl.tar.gz
        dest: /tmp
    - unarchive:
        src: bat-{{latest_release.stdout}}-x86_64-unknown-linux-musl.tar.gz
        dest: /tmp
    - copy:
        src: /tmp/bat-{{latest_release.stdout}}-x86_64-unknown-linux-musl/
        dest: /usr/local/bat/
        mode: preserve
    - lineinfile:
        path: ~/.bashrc
        line: "alias bat='/usr/local/bat/bat'"
        insertafter: 'mv'
    - find:
        paths: /tmp
        file_type: any
        patterns: bat*
      register: bat_files_delete      
    - file:
        path: "{{ item.path }}"
        state: absent
      with_items: "{{ bat_files_delete.files }}"

sudo sh -c 'wget https://github.com/sharkdp/bat/releases/download/v0.12.1/bat-v0.12.1-x86_64-unknown-linux-musl.tar.gz -O - |tar -xvzf - -C /usr/local/bin && mv /sr/local/bin/bat-v0.12.1-x86_64-unknown-linux-musl/bat /usr/local/bin/bat'

CentOS 7 - Installing the latest bat command release version from GitHub

Note: For more information, please see sharkdp/bat GiHub repo.

Creating the Installer Script

Create the install_bat.sh file, with:

#!/bin/sh

red=`tput setaf 1`
green=`tput setaf 2`
bold=`tput bold`
reset=`tput sgr0`

echo ""
echo "${bold}${green}Installing the latest CentOS release version of bat command from GitHub...${reset}"

echo ""
echo "${bold}Note${reset}: For more information, please see https://github.com/sharkdp/bat."

echo ""
echo "Finding the latest version tag from Github..."

BAT_VERSION=$(curl --silent "https://api.github.com/repos/sharkdp/bat/releases/latest" | grep -Eo '"tag_name": "v(.*)"' | sed -E 's/.*"([^"]+)".*/\1/')
BAT_RELEASE="bat-$BAT_VERSION-x86_64-unknown-linux-musl"
BAT_ARCHIVE="$BAT_RELEASE.tar.gz"

echo ""
echo "Version ${bold}$BAT_VERSION${reset} found, downloading ${bold}$BAT_ARCHIVE${reset} from GitHub..."

curl -sOL "https://github.com/sharkdp/bat/releases/download/$BAT_VERSION/$BAT_ARCHIVE"

echo ""
echo "Unarchiving ${bold}$BAT_ARCHIVE${reset} to ${bold}$HOME/$BAT_RELEASE${reset}..."

tar xzvf $BAT_ARCHIVE -C $HOME/

echo ""
echo "Copying executable to ${bold}/usr/local/bin/bat${reset}..."

sudo sh -c "cp $HOME/$BAT_RELEASE/bat /usr/local/bin/bat"

echo ""
echo "Removing ${bold}$BAT_ARCHIVE${reset} and cleaning up..."

rm $BAT_ARCHIVE

unset BAT_ARCHIVE
unset BAT_RELEASE
unset BAT_VERSION

if command -v bat &> /dev/null
then
  echo ""
  echo "${bold}${green}Finished installing $(bat --version).${reset}"
else
  echo ""
  echo "${bold}${red}Installation failed! Please examine this script and try steps manually.${reset}"
  exit 1
fi

Make the script executable:

chmod +x install_bat.sh

Installing or Updating

Run the script to install the bat command:

./install_bat.sh

Note: You can run the script at any time later to update bat to the latest version.

Quick Install

Alternatively, you can use the following "command" to install bat:

V=$(curl --silent "https://api.github.com/repos/sharkdp/bat/releases/latest" | grep -Eo '"tag_name": "v(.*)"' | sed -E 's/.*"([^"]+)".*/\1/') && curl -sOL "https://github.com/sharkdp/bat/releases/download/$V/bat-$V-x86_64-unknown-linux-musl.tar.gz" && tar xzvf "bat-$V-x86_64-unknown-linux-musl.tar.gz" -C . && sudo sh -c "cp ./bat-$V-x86_64-unknown-linux-musl/bat /usr/local/bin/bat" && rm bat-$V-x86_64-unknown-linux-musl.tar.gz && unset V

Thanks, @msrdjan
Quick Install
works for me on _Centos8.2_

Was this page helpful?
0 / 5 - 0 ratings

Related issues

antoinemadec picture antoinemadec  路  3Comments

HakubJozak picture HakubJozak  路  3Comments

scalp42 picture scalp42  路  3Comments

sharkdp picture sharkdp  路  3Comments

x70b1 picture x70b1  路  3Comments