Skip to content

Instantly share code, notes, and snippets.

@rain1024
Last active November 15, 2024 16:03
Show Gist options
  • Save rain1024/98dd5e2c6c8c28f9ea9d to your computer and use it in GitHub Desktop.
Save rain1024/98dd5e2c6c8c28f9ea9d to your computer and use it in GitHub Desktop.
Install pdflatex ubuntu

PdfLatex is a tool that converts Latex sources into PDF. This is specifically very important for researchers, as they use it to publish their findings. It could be installed very easily using Linux terminal, though this seems an annoying task on Windows. Installation commands are given below.

  • Install the TexLive base
sudo apt-get install texlive-latex-base
  • Also install the recommended and extra fonts to avoid running into the error [1], when trying to use pdflatex on latex files with more fonts.
sudo apt-get install texlive-fonts-recommended
sudo apt-get install texlive-fonts-extra
  • Install the extra packages,
sudo apt-get install texlive-latex-extra

Once installed as above, you may be able to create PDF files from latex sources using PdfLatex as below.

pdflatex latex_source_name.tex

Error 1: grep: ptmr7t.log: No such file or directory mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input ptmr7t' failed to make ptmr7t.tfm. kpathsea: Appending font creation commands to missfont.log.

! Font OT1/ptm/m/n/10=ptmr7t at 10.0pt not loadable: Metric (TFM) file not found.

Ref: http://kkpradeeban.blogspot.com/2014/04/installing-latexpdflatex-on-ubuntu.html

@AyubIman
Copy link

Thank you very much, friend.

@dataplayer12
Copy link

Thanks! Worked perfectly.

@rishi23root
Copy link

Hey, can you tell me the version you are getting using this method?

@raquelhortab
Copy link

I think this installs an old version of latex (2021) and now I get some version warnings when trying to install newer packages

@yspkm
Copy link

yspkm commented Oct 1, 2023

Thank you :)

@rishi23root
Copy link

I think this installs an old version of Latex (2021) and now I get some version warnings when trying to install newer packages

I am facing the same issue also the installation is too heavy, quite time taken and not 2023 version

@rishi23root
Copy link

rishi23root commented Oct 2, 2023

To install TexLive 2023 as light as possible (according to me ;) ) with working Pdflatex

bash script code -->

#!/usr/bin/env bash

set -e -o pipefail


# PARSING COMMANDLINE ARGUMENTS *******************************************

# Where all the installed TeX Live goes. It defaults to a directory in your
# home called "texlive".
prefix=~/texlive
# Select the scheme to install. By default, it is "minimal".
scheme=scheme-minimal
# Tell the installer location, that is the directory where to put all the 
# stuff needed for the installation.
installer_dir=~/.texlive-installer
# Verify the installer before running it? By default, do not do it. It is
# recommended to do so, though.
verify_installer=no
# Write a file to be sourced and which exports new paths containing those
# ones of TeX Live
texliverc=~/.tlrc
# By default, adjust ~/.bashrc to register the new paths for TeX Live. 
adjust_bashrc=yes

# Parsing the commandline arguments.
while [ $# -gt 0 ]; do
  case $1 in
    --prefix=*)
      prefix=${1#*=}
      shift
    ;;
    --scheme=*)
      scheme=scheme-${1#*=}
      shift
    ;;
    --installer-dir=*)
      installer_dir=${1#*=}
      shift
    ;;
    --verify-installer)
      verify_installer=yes
      shift
    ;;
    --tlrc=*)
      texliverc=${1#*=}
      shift
    ;;
    --no-adjust-bashrc)
      adjust_bashrc=no
      shift
    ;;
    *)
      echo ":: unknown option: $1"
      exit
    ;;
  esac
done


## PREPARING FOR THE INSTALLER ********************************************

# Let us choose a directory where to download the installer and move there.
[ -d $installer_dir ] || mkdir -p $installer_dir
cd $installer_dir

echo -n ":: download install-tl-unx.tar.gz... "
wget -q https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
if [ $? -eq 0 ]
  then echo "OK"
  else
    echo "ERROR!"
    exit
fi

if [ $verify_installer == yes ]; then
  echo ":: verifying the installer... "
  wget -q http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz.sha512
  wget -q http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz.sha512.asc
  wget -q https://tug.org/texlive/files/texlive.asc
  
  sha512sum -c install-tl-unx.tar.gz.sha512

  gpg --quiet --import texlive.asc
  sig1=$(gpg --list-keys | sed -n '4p' | sed 's/ //g')
  sig2=$(gpg --verify install-tl-unx.tar.gz.sha512.asc 2>&1 | sed -n '7p' | sed -E 's/^[^:]+://;s/ //g')

  if [ $? -eq 0 ]
    then
      echo ":: OK"
    else
      echo ":: Cannot verify!"
      read -n 1 -p ":: continue anyway? (y/n) " ans
      [ $ans = y ] || exit 1
  fi
fi

echo ":: unpacking the installer..."
tar -xzf install-tl-unx.tar.gz --strip-components 1


## INSTALLATION PROCESS ***************************************************

echo ":: starting the installer..."
TEXLIVE_INSTALL_PREFIX=$prefix ./install-tl \
  --scheme $scheme --no-interaction

## POST-INSTALLATION PHASE ************************************************

# Fix PATH, so that we make TeX Live programs visible. To do so, we need to
# extract the year that is also the version of the TeX Live just installed.
year=`sed -n '1p' release-texlive.txt | sed -E 's/^[^0-9]+//g'`

# install pdflatex 
$prefix/$year/bin/x86_64-linux/tlmgr install latex-bin

# Write an appropriate file in $HOME.
cat <<EOF > $texliverc
#!/bin/sh

# Adding TeX Live paths...
export PATH=$prefix/$year/bin/x86_64-linux:\$PATH
export MANPATH=$prefix/$year/texmf-dist/doc/man:\$MANPATH
export INFOPATH=$prefix/$year/texmf-dist/doc/info:\$INFOPATH
EOF

[ $adjust_bashrc == yes ] && cat <<EOF >> ~/.bashrc

# Register TeX Live paths
[ -f $texliverc ] && source $texliverc

EOF

# EXPERIMENTAL | After you have done all the work above, prepare the an
# uninstaller for the installed TeX Live.
cat <<EOF > ~/.texlive-uninstaller
#!/bin/sh
rm -rfv $prefix
rm -rfv ~/.texlive*
rm -rfv ~/.texlive-uninstaller
EOF

chmod u+x ~/.texlive-uninstaller

echo ":: END!"

most important part is - tlmgr install latex-bin
for more info check https://github.com/rishi23root/resume-curator/tree/server/scripts where I am currently using this trick in production

@himloul
Copy link

himloul commented Dec 22, 2023

Thank you :)

@Yelinz
Copy link

Yelinz commented Jan 5, 2024

https://askubuntu.com/questions/1429846/how-can-i-install-latex-on-ubuntu-20-04-5

Only doing this worked for me aswell sudo apt install texlive

@piiskop
Copy link

piiskop commented Jan 16, 2024

I do it on 22.04 and get:

sudo apt-get install texlive-latex-base

[sudo] password for kalmer:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
texlive-latex-base is already the newest version (2021.20220204-1).

I do it on 23.10 and get:

sudo apt-get install texlive-latex-base

[sudo] password for kalmer:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
texlive-latex-base is already the newest version (2023.20230613-3).

How can I get the newest pdflatex on 22.04 that recognizes hyphenation in other languages than English?

@rishi23root
Copy link

I do it on 22.04 and get:

sudo apt-get install texlive-latex-base

[sudo] password for kalmer:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
texlive-latex-base is already the newest version (2021.20220204-1).

I do it on 23.10 and get:

sudo apt-get install texlive-latex-base

[sudo] password for kalmer:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
texlive-latex-base is already the newest version (2023.20230613-3).

How can I get the newest pdflatex on 22.04 that recognizes hyphenation in other languages than English?

use this code to install latest text-live on 22.04 and use 'tlmgr' to install any required extra package,

i hope it helps

@rishi23root
Copy link

https://askubuntu.com/questions/1429846/how-can-i-install-latex-on-ubuntu-20-04-5

Only doing this worked for me as well sudo apt install texlive

can you please share more details because i want to achieve the same but i am not able to get latest version on text-live

@piiskop
Copy link

piiskop commented Feb 10, 2024

Maybe it is dangerous to install texlive's latest version as it might not work with your operating system. I guess this is why different operating systems have different versions of texlive available.

@rishi23root
Copy link

I wouldn't say it is dangerous, rather it is tricky to make it work

@rsarrazin2
Copy link

To generate PDFs as mentioned in How to create a PDF-out-of-Sphinx-documentation-tool, I had to install all of the above plus latexmk.

@turbcool
Copy link

turbcool commented Jul 8, 2024

To generate png using latexpdf, i had to install all of the above plus ghostscript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment