One way to solve error: "externally-managed-environment" is to create a virtual environment folder in your root path. By creating and using a virtual environment, you bypass the system Python entirely, allowing you to install and manage packages freely without impacting the system-wide Python installation.
sudo apt install python3-pip
sudo apt install python3.13-venv
python3 -m venv ~/py_envs
source ~/py_envs/bin/activate
python3 -m pip install yt-dlp
python3 -m pip install --upgrade yt-dlp
Before executing the 2nd command above, you can try executing first the 3rd command to see if the prompt returns a newer version suggestion than python3.13-venv
yt-dlp is a better option with more functionalities. It's a fork from the youtube-dl
Note: After you leave the virtual environment, if you need to use yt-dlp again, you have to first execute the 3rd and 4th commands above to set the virtual environment.
Since this is installed in a virtual environment, you won't get notices of new versions available, so you have to run the 6th command above to check if there's an update ready to be installed.
Sometimes the yt-dlp command may return an error when trying to download a video, in most cases that's fixed installing the new version.
Thre's a lot of information and help in the manual:
man yt-dlp
If you want to check first all the available formats of a YouTube video you need the URL of it along with the flag "-F" after the yt-dlp command:
yt-dlp -F https://www.youtube.com/watch?v=wh-07BzfgYY
And you will have an output like the following:
There will be a list of all the formats with IDs, formats, resolutions, video and audio codecs used, file sizes, extensions, FPS, if video or audio only, etc.
The command to download the format of your preference, by example if ID 18 do the following now using the lower case flag "-f" :
yt-dlp -f 18 https://www.youtube.com/watch?v=wh-07BzfgYY
sudo apt install ffmpeg
Then you can download and merge, by example ID 396 (video only) plus ID 139 (audio only) with the following command:
yt-dlp -f 396+139 https://www.youtube.com/watch?v=wh-07BzfgYY
Note: It's possible to download videos not only from YouTube.
-----------------------
The following produce an error and now it has been deprecated. It's better to use a virtual environment as shown here above:
sudo apt install python3-pip
sudo pip3 install --upgrade youtube-dl
-----------
The following is also deprecated:
sudo apt install python-pip
sudo pip install youtube-dl
If you want to upgrade youtube-dl
sudo pip install --upgrade youtube-dl
or, if necessary
sudo pip install youtube-dl
If you want to upgrade youtube-dl
sudo pip install --upgrade youtube-dl
or, if necessary
sudo pip install --upgrade pip
The following method of installation is even older and deprecated, it's here just as a reference:
sudo apt-get install python-setuptools
sudo easy_install pip