Update: use yt-dlp instead of youtube-dl! It's a fork off of youtube-dl and is much better-maintained and works much better! See a little more on yt-dlp in my answer here.
Original answer:
First, ensure you have the latest version of youtube-dl installed.
How to install the latest version of youtube-dl
See:
- https://github.com/ytdl-org/youtube-dl/#installation
- https://github.com/ytdl-org/youtube-dl/#how-do-i-update-youtube-dl
Run these commands:
# On Linux Ubuntu:
1. Check your current version
youtube-dl --version
2.Uninstall your current version, if necessary
sudo apt remove -y youtube-dl
3. Now, install the latest version
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
4. Check your current version to ensure it updated
youtube-dl --version
How to get the best video quality available.
This answer here, with the most votes, should be right to give you the best video quality available, but....it's not always. bestvideo+bestaudio seems to choose only the best video and best audio of the options that are video only and audio only, then it merges the two together. Note that this also appears to be identical to the default behavior of youtube-dl. However, on the video I was looking at, the best quality was a single, pre-merged file that was already in a format with combined video and audio. The bestvideo+bestaudio option did NOT choose this best quality 720p file because it was looking only for separate video and audio files. Details below.
Solution? Have it grab the best single file which contains both video and audio in one instead, with this:
youtube-dl -f best 'https://youtu.be/FWGC9SqA3J0'
In short: to get the best quality, you may need to use the -f best option, NOT the -f bestvideo+bestaudio option! Try both to see. It could vary from video to video.
Quick reference of various examples of youtube-dl in general
I need a quick place to look for common commands. Here are some:
# View the help menu (then press `/` to do a regular expression search`)
youtube-dl --help | less
List all available format you can download for this video with
-F or --list-formats
youtube-dl -F 'https://www.youtube.com/watch?v=-FzqOdRpCGw'
youtube-dl --list-formats 'https://www.youtube.com/watch?v=-FzqOdRpCGw'
Download the best single file containing both audio and video already
merged into one file
youtube-dl -f best 
    'https://www.youtube.com/watch?v=-FzqOdRpCGw'
Download the best stand-alone video file and the best **stand-alone audio
file** and then combine them into one file
youtube-dl -f 'bestvideo+bestaudio' 
    'https://www.youtube.com/watch?v=-FzqOdRpCGw'
Use -o or --output to specify the name of the output file.
- See the "OUTPUT TEMPLATE" section here for all of the metadata tags you can
use to auto-generate parts of the filename:
https://github.com/ytdl-org/youtube-dl/#output-template
youtube-dl -f 'bestvideo+bestaudio' 
    'https://www.youtube.com/watch?v=-FzqOdRpCGw' --merge-output-format mkv 
    -o 'best_merged.mkv'
[includes auto-generated subtitles]
time the whole download, saving YouTube's autogenerated subtitles into
the video too, AND choosing a custom name for the output file, with the
extension specified using the meta-data template format $(ext)s. See link
below for more metadata format examples.
time youtube-dl -f best --write-auto-sub 
    'https://www.youtube.com/watch?v=2WoDQBhJCVQ' -o 'greatest_shot.%(ext)s'
See also:
- https://github.com/ytdl-org/youtube-dl/#output-template
- More metadata format examples for the filename: https://github.com/ytdl-org/youtube-dl/#output-template-examples
- Super User: How to download only subtitles of videos using youtube-dl
Proof that -f best is better than -f bestvideo+bestaudio in at least some cases:
(Note: all circuit schematic images below are actually screenshots from this electrical-engineering-related video tutorial: Video One- Getting started with LTspice).

More specifically, see below for the results of running
youtube-dl -F 'https://youtu.be/FWGC9SqA3J0'
in order to see what video 'F'ormats are availabe for download:
gabriel ~ $ youtube-dl -F https://youtu.be/FWGC9SqA3J0
[youtube] FWGC9SqA3J0: Downloading webpage
[youtube] FWGC9SqA3J0: Downloading video info webpage
[youtube] FWGC9SqA3J0: Downloading MPD manifest
[youtube] FWGC9SqA3J0: Downloading MPD manifest
[info] Available formats for FWGC9SqA3J0:
format code  extension  resolution note
139          m4a        audio only DASH audio   50k , m4a_dash container, mp4a.40.5@ 48k (22050Hz), 2.30MiB
249          webm       audio only DASH audio   51k , opus @ 50k, 2.34MiB
250          webm       audio only DASH audio   62k , opus @ 70k, 2.85MiB
171          webm       audio only DASH audio  103k , vorbis@128k, 4.68MiB
251          webm       audio only DASH audio  109k , opus @160k, 5.10MiB
140          m4a        audio only DASH audio  130k , m4a_dash container, mp4a.40.2@128k (44100Hz), 6.13MiB
160          mp4        256x138    DASH video  108k , mp4_dash container, avc1.4d400b, 24fps, video only
134          mp4        640x348    DASH video  142k , mp4_dash container, avc1.4d401e, 24fps, video only, 3.42MiB
133          mp4        426x232    DASH video  242k , mp4_dash container, avc1.4d400c, 24fps, video only
136          mp4        1280x694   DASH video  473k , mp4_dash container, avc1.4d401f, 24fps, video only, 8.01MiB
135          mp4        854x464    DASH video 1155k , mp4_dash container, avc1.4d4014, 24fps, video only
17           3gp        176x144    small , mp4v.20.3, mp4a.40.2@ 24k, 1.63MiB
36           3gp        320x174    small , mp4v.20.3, mp4a.40.2, 2.98MiB
43           webm       640x360    medium , vp8.0, vorbis@128k, 7.44MiB
18           mp4        640x348    medium , avc1.42001E, mp4a.40.2@ 96k, 8.54MiB
22           mp4        1280x694   hd720 , avc1.64001F, mp4a.40.2@192k (best) 
Notice that row 22 says "(best)" to the far right of it. This is the only option which offers hd720 quality, which is the best quality I can get when watching this video in a web browser on YouTube. It is the clearest and has the best definition. When I use either of the commands recommended by the top answer:
youtube-dl -f 'bestvideo+bestaudio' 'https://youtu.be/FWGC9SqA3J0'
OR:
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 'https://youtu.be/FWGC9SqA3J0'
I end up with a video that is both lower quality/lower resolution, and has a larger file size. I don't understand it exactly, but the -f best option is definitely the only one that truly gives me the best resolution.
Here's some screenshots from a tutorial video I was watching showing electronic circuit diagrams in the video. Notice how the latter one is much higher quality and more legible (click on each image and compare the tiny font in a zoomed-in view):
- Using the lower quality -f bestvideo+bestaudiooption accepted here as the right answer (OR just using the default option:youtube-dl 'https://youtu.be/FWGC9SqA3J0'):
 
- Notice how fuzzy the icons are at the top, and how difficult to read are the open window and tiny words within it!
- This is significantly worse than the quality I get when watching online at YouTube directly in the browser.
- This option also takes up more memory for some reason: the video is 18.0 MB, and it took longer for my system to download and re-combine (audio + video) than the -f bestoption below, which only had to do one download and no recombining since it was already one file.
- Using the higher quality -f bestoption which I recommend:
 
- Notice how much clearer the small icons at the top and small font in the window are!
- This is the identical resolution to what I get when watching in the highest resolution possible directly in the browser on YouTube.
- This option also takes up less memory for some reason: the video is 14.8 MB.
Additional Reading:
- See man youtube-dlfor details.
- My answer here: How can I update youtube-dl?. This also solves the problem:
WARNING: unable to download video info webpage: HTTP Error 410: Gone