Saturday, April 20, 2024
HomeTutorialsHow to Play MP3 by Command line in Linux Distros

How to Play MP3 by Command line in Linux Distros [Tutorial]

Linux terminal is the most powerful handy tool that comes pre-installed on every Linux distributions. We use the terminal shell to install, run, and remove applications and tools with different terminal commands. But, did you know that you can also use the terminal shell to play your favorite MP3 music via different command lines? Playing MP3 files via command lines doesn’t only make you smart; it is also very efficient and time-saving. Besides these, you can get a unique and different flavors music player by playing MP3 files via the terminal command lines.

Play MP3 by Command Line


Normally, we use different GUI-based media players to open MP3, mp4, and other multimedia files. Using Linux with the command-line interface is preferable and hassle-free; we can play MP3 files by the command-line interface.

Most Linux users prefer the command-line-based user I/O method to operate their system. Moreover, some tools provide detailed information about the running MP3 file in the command shell. In this post, we will use the VLC media player, MPG123, and a few other tools to play MP3 audio files by command line on our Linux system.

Method 1: Use VLC Functions to Play MP3 by Command Line


Video Lan Client (VLC) media player is mostly used on Linux to watch movies and high-quality videos. As the VLC player uses an extensive amount of multimedia library codec, you can use those media library functions to open MP3 files by command line. Here, in this method, we will use the ncurses media library function of the VLC player to open MP3 files by command line.

Step 1: Install VLC Media Player


First, we will install the VLC media player on our Linux system. Later, we will use the VLC library plugins to play MP3 files by command line. Here, several methods are shown to install the VLC player on different Linux distributions. As I am writing for all Linux distributions, you have to go through the entire post and find the appropriate steps for your specific distribution.

1. Install VLC on Ubuntu and Debian Distributions


If you are a Debian or Ubuntu Linux user, you can install the VLC player directly on your system by running the following APT URL. You need to copy the APT URL, paste the URL in any web browser, and hit the Enter button. It will automatically open the software installation tool and install the VLC and other additional packages for VLC.

apt://vlc

Suppose you want to use the terminal command shell to install packages on your system. In that case, you can install the VLC media player on your Debian system by running the following aptitude command lines given below on your terminal shell.

Install VLC via APT

sudo apt update
sudo apt install vlc
2. Install VLC in Manjaro

Manjaro and other Arch Linux users can install the VLC media player on their system by funning the following packman command given below. The package will automatically install and configure the necessary media library functions and the media codec packages on your Arch Linux system.

sudo pacman -S vlc qt4

manjaro Vlc mp3 by command line

3. Install VLC on Fedora, CentOS, and Red Hat Linux

If you are a Red Hat, Fedora, or CentOS user, you can install the VLC media player on your Linux system by running the following command-lines on your terminal shell. As Red Hat and other Linux distributions don’t always have the package repositories updated, first, we need to install the RPM Fusion packages on our system.

Here, I am showing only the DNF commands for Fedora Linux; you can change the DNF commands to RPM command according to your distribution requirement.

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Once the fusion packages are installed successfully, you can now run the following command to install the VLC media player.

sudo dnf install vlc

Step 2: Play MP3 by Command Line


Once the VLC is downloaded, you can now play MP3 files on your Linux system by command line. First, you need to know where the MP3 files are stored inside your Linux filesystem. Let you have stored the MP3 files in the Downloads directory. In that case, we will open the Downloads directory, see the list of the files and run the NVLC command to play the specific MP3 file by the command-line interface.

You can use the following command lines to play the MP3 files using the terminal shell interface. I must mention that you can follow this step on all Linux distributions.

cd Downloads/
ls
nvlc Music1.mp3

MP3 by command line directory

If you want to add all your songs to the queue list, you can create a playlist and play the MP3 files by the command-line interface. To add a music directory to the playlist, run the following command line on your Linux terminal shell.

nvlc /home/ubuntupit/Downloads/Music/

You can also use the following CVLC command to play MP3 files by the command line on your Linux system.

cd Downloads/
ls
cvlc Music1.mp3

MP3 by command line CVLC

Method 2: Use MPG123 Tool to Play MP3 by Command Line


This method will see how to play MP3 files by using the MPG123 command-line based music player. First, we will see how to install the MPG123 player on various Linux distributions; later, we will know how to play MP3 files by command line.

Step 1: Install MPG123 on Linux


In this step, I will demonstrate how you can get the MPG123 on Debian, Arch, and Red Hat Linux. I have chosen Ubuntu to cover the Debian distributions, Manjaro, to cover the Arch Linux, and Fedora to cover the Red Hat Linux Enterprise. If you are using any other Linux distributions, you can replace the package management command from the command-lines.

1. Install MPG123 on Ubuntu Linux

The MPG123 player was famous in the earlier versions of Linux distributions. Nowadays, the MPG123 player is not used very much to open media files. However, run the following aptitude package management command-lines to install the MPG123 player on your Ubuntu system.

sudo apt update
sudo apt -y install mpg123

MP3 by command line install mpg123

Once the installation is done, you can run the following help command to understand the syntaxes of the MPG123 package.

mpg123 --help

You can find the MPEG layer applications on your software store on Ubuntu and other Debian distributions. You can also download the MPEG 123 from the Store.

2. Install MPG123 On Fedora Linux

To install the MPG123 tool on your Fedora and Red Hat-based Linux distributions, first, you need to install the EPEL (Extra Packages for Enterprise Linux) releases from the system repository. Then you can install the MPG123 package on your system.

Run the following DNF and RPM commands to install the EPEL and Red Hat extra packages on your Linux system.

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf upgrade
sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"

After the EPEL packages are installed inside our system, we will now use the SNAP package manager to install the MPG123 tool on our Fedora and RHEL system. To run the SNAP commands, we need to get the SNAP installed inside our system. You can run the following command-lines on your Linux terminal shell to install the MPG123 tool on your Fedora workstation and Red Hat Linux system.

Install the SNAPD on your Linux system.

sudo yum update
sudo yum install snapd

Enable the SNAPD Socket on your system.

sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

Finally, install the MPG123 package on your Linux system.

sudo snap install mpg123-cm
3. Install Mpg123 on Manjaro

Installing MPG123 on Manjaro and other Arch-based Linux distributions are pretty straight forward. You can run the following packman command on your terminal shell to install the MPG123 on your Manjaro Linux.

sudo pacman -Sy mpg123

Step 2: Play MP3 by MPG123 Command Line


Once the installation is finished, you can now play MP3 files on your Linux system by the command-line interface. To play MP3 files via the MPEG tool, you can open your terminal shell and run the following command-line instructions given below.

First, you have to open the Music directory where the MP3 files are stored. Then you can run the following mpg123 command to play the MP3 file.

cd Downloads
ls
mpg123 Music1.mp3

MP3 by command line play via mpg123

You can add all your MP3 files from any directory to the MPG playlist by the command line. To add all MP3 files to your playlist, run the following command on your terminal shell. This command will add files chronologically.

mpg123 *.mp3 

You can shuffle the MP3 files on your playlist. Run the following -Z command to shuffle the MP3 files.

mpg123 -Z *.mp3

Method 3: Use FFmpeg Library to Play MP3 by Command Line


FFmpeg is an open-source and easy executable media tool for Linux and other operating systems. FFmpeg can convert, stream, and recognize the file type. You can also extract an MP3 file from mp4 or other video files and transcode AAC to MP3 through the FFmpeg tool. In this method, we will see how to install the FFmpeg on our Linux system and play MP3 files using the FFmpeg command line.

Step 1: Install FFmpeg on Linux


Linux distributions don’t always have the necessary media library functions pre-installed inside the system. Installing the FFmpeg media library functions are pretty simple on Linux. Here, we will learn the methods of installing the FFmpeg tool on various Linux distributions.

1. Install FFmpeg on Ubuntu

If you are a Ubuntu or Debian user, you can run the following aptitude package commands on your terminal shell to install the FFmpeg tool on your system. After the installation is done, you can check the version of the FFmpeg tool to check whether the tool is installed correctly or not.

sudo apt update
sudo apt install ffmpeg
ffmpeg -version
2. Install FFmpeg on Fedora

Fedora Linux users can run the following DNF commands to install the FFmpeg tool on the system. These commands are used to download and install the RPM fusion packages on the Fedora system from the Linux repository.

sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

download RPM Fusion

Now, run the following DNF commands in your terminal shell to install the FFmpeg tool on your Fedora Linux. 

sudo dnf -y install ffmpeg
sudo dnf -y install ffmpeg-devel

DNF Ffmpeg mp3 by command line

2. Install FFmpeg on Manjaro and Arch

Manjaro and Arch-based Linux users can install the FFmpeg tool on their system from the Snap store. First, we will install the Snap package then we will see how to install the FFmpeg tool via the Snap package manager.

Run the following Pacman commands to get the Snap package manager on your Manjaro Linux.

sudo pacman -S snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

Now, run the following command on your terminal shell to install the FFmpeg tool on your Manjaro Linux.

sudo snap install ffmpeg

If you find any error while installing the FFmpeg tool, run the following Pacman commands given below to avoid and bypass the errors.

sudo pacman -S ffmpeg 
sudo pacman -Rs ffmpeg

Step 2: Play MP3 by FFmpeg


After the installation is done, you can now use the FFmpeg tool to play MP3 files by command line on your Linux system. First, locate the filesystem directory where you stored the MP3 files. Then type ffplay and then type your song name and hit the Enter button.

cd Downloads
ls
ffplay Music1.mp3

Fedora FFPlay

Method 4: Play MP3 by Command Line Using the MPlayer


Linux users can use the MPlayer to play both audio and video files by command line. This method will only cover how you can install the MPlayer and play MP3 files by command line using the MPlayer plugins on your Linux system.

Step 1: Install MPlayer on Linux


As the MPlayer is a very popular application among the Linux community, the package repository and other library tools are available for all Linux distributions. Here, we will see the methods of installing the MPlayer on Ubuntu, Fedora, and Manjaro Linux.

1. Install Mplayer on Ubuntu

The package repository of the MPlayer is available on the official repository of Linux. If you are a Ubuntu and other Debian Linux user, you can install the MPlayer on your system by running the following aptitude package manager commands.

$ sudo add-apt-repository universe
$ sudo apt update
$ sudo apt install mplayer MPlayer-gui
2. Install MPlayer on Manjaro

Manjaro and other Arch-based Linux users can install the MPlayer on their system by running the following Pacman commands. Manjaro users can run the keyring command given below to make the installation process secure and safe.

sudo pacman -S archlinux-keyring manjaro-keyring

Now, run the following Pacman commands to install the MPlayer on your Arch Linux.

sudo pacman -S mplayer
sudo pacman -Rs mplayer

Mplayer Manjaro mp3 by command line

3. Install Mplayer on Fedora Linux

Red Hat, Fedora, and CentOS require the additional RPM fusion functions to configure the MPlayer on the Linux system. You can run the following DNF commands to install the RPM fusion functions on your Red Hat Linux Enterprise Linux.

$ sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

Now, run the following DNF command to install the MPlayer on your Fedora Linux. Red Hat Linux users might replace the DNF command with the RPM command.

$ dnf install mplayer

You can also install the MPlayer manually on your Linux system by downloading the compressed file of the MPlayer. You can download the compressed MPlayer and other codes from here.

Step 2: Play MP3 Files By Command Line


After the MPlayer is installed in your Linux system, you can now open your MP3 directory and play mp3 files by command line. First, open the mp3 directory and type mplayer then type the name of your desired MP3, then hit the enter button to play the file.

cd Downloads/
ls
mplayer music-file.mp3

To add all the MP3 files from the directory to your playlist, run the following command on your terminal shell.

mplayer *.mp3

MPlayer Manjaro mp3 by command line

You can shuffle the MP3 files and play randomly by the command line.

mplayer -shuffle *.mp3

You can also play one specific MP3 file in a loop.

mplayer -loop music-file.mp3

Method 5: Play MP3 Files by SOX


Mainly, the Sox tool is used to convert and play MP3 and other audio files using the command-line interface. However, we can use the Sox tool to play MP3 files by command line on the Linux system. First, we will install the Sox tool, and then we will use the Sox tool to play MP3 files.

Step 1: Install Sox on Linux Distributions


In this step, we will see how you can install the Sox tool on various Linux distributions. As the Sox tool is available for almost every Linux distributions, we can install the package using Linux’s official package management commands.

1. Install Sox on Ubuntu

Ubuntu and other Debian Linux users can install the Sox tool on their system by running the following aptitude package management commands on the terminal shell. You must update your system repository before running the installation commands.

sudo apt update
sudo apt install sox
sudo apt install libsox-fmt-all

mp3 by command line SOX on Ubuntu

2. Install Sox on Fedora and Red Hat

Installing the Sox player is very straight forward and effortless on Red Hat-based Linux machines. Fedora users can run the following DNF command to install the Sox tool on your Linux system.

sudo dnf install sox

Red Hat and other Linux users can run the RPM command given below to install the Sox on your system.

yum install sox
3. Install Sox on Arch

Installing Sox on Arch, Manjaro, and other Arch-based Linux distributions are very simple. You just need to run the following Pacman command on your terminal shell to install the Sox tool on your system.

sudo pacman -S sox

Arch SOX mp3 by command line

Step 2: Play MP3 by SOX


After the installation of SOX is done, we can now play MP3 files by command line. First, we have to find the directory where the files are stored. Let’s assume the files are stored in the Downloads directory; in that case, we can use the cd commands to open the directory.

cd Downloads/
ls

Now, type play and write down the name of your desired MP3 file, then hit the Enter button to play the MP3 file by the command line.

play music-file.mp3

To add all MP3 files from the directory to the playlist, run the following command.

play *.mp3

Extra Tip: Play Youtube Songs by Command Line


If you want to play your favorite kinds of music using your Linux system’s command-line interface, you can use the MPS-Youtube tool. The MPS Youtube is supported for most of the Linux distributions. It allows the user to search, edit, download, and encode the youtube videos by the command line. Here, you can find the additional information and source codes of the MPS Youtube on GitHub.

Now, we will see how you can install the MPS Youtube on various Linux distributions. Debian and Arch-based Linux users can follow the command-lines given below to get the MPS Youtube.

Install MPS-Youtube on Ubuntu/Debian system.

sudo apt-get update -y
sudo apt-get install -y mps-youtube

Install MPS Youtube on Manjaro and other Arch-based Linux.

sudo pacman -S mps-youtube

After the installation is done, you can open the MPS Youtube using the terminal shell on your Linux system. Run the following command to open the MPS Youtube.

mpsyt

You can now use the search options to find and play your desired music from YouTube via the command-line interface on Linux.

MPYT on Linux

Ending Words


We have seen five methods of playing MP3 files by command line in the Linux system in the entire post. I have described how you can use the nVLC, cVLC, FFmpeg, MPG, and other media library functions to play MP3 files from your Linux filesystem using the command-line interface. A few more tools are also available on the web to play MP3 by command-line that hasn’t been listed in this post. You can find and try them if you want.

If you find this post useful and handy, please share it with friends and the Linux community. You can share which media player or tool you use to play MP3 files on your Linux system. If you have anything to share or ask, you are welcome to write down your opinions regarding this post in the comment section.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

You May Like It!

Trending Now