• First install LaTeX. For this open terminal and type
    $ sudo apt-get install texlive-full
  • Install SAGE
    Download binaries from their website for this

    Go to the website http://sagemath.org/download.html  and pick up a mirror to download. Choose Download for Linux, then

    1. Choose your architecture (32 or 64 bit)
    2. Then choose the ‘lzma’ package with the word Ubuntu and your Ubuntu version in the name.For example, for a 32-bit processor running Ubuntu 10.4, you’d select sage-4.4.4-linux-32bit-ubuntu_10.04_lts-i686-Linux.tar.lzma where 4.4.4 is the latest Sage version at the time of writing.After this do following
      $ cd /opt
      $ sudo tar --lzma -xvf /path_to_sage_package/sage-?.?.?-linux-ubuntu-...lzma
      $ sudo ln -s /opt/sage.?-?-?.../sage /usr/local/bin/sage
      After this type 
      $ sage
      Viola! SAGE installed

Problem Faced By Me:

Usually when you upgarde your sage version then there is possibility of one basic problem that:

sagetex.sty file of sage and sagetex.sty file of texlive are of different versions. So whenn we run command latex filename.tex, it compile and give filename.sagetex.sage . Now to compile this, we do sage filename.sagetex.sage.

To solve this:

  • Firstly remove sagetex.sty file of Tex from /usr/share/texmf-texlive/tex/latex/sagetex. To make TeX aware of sagetex.sty is to copy that file into a convenient place in your home directory. In most TeX distributions, the texmfdirectory in your home directory is automatically searched for packages. To find out exactly what this directory is, do the following on the command line:
    kpsewhich -var-value=TEXMFHOME

    which will print out a directory, such as /home/username/texmf or /Users/drake/Library/texmf. Copy the tex/ directory from SAGE_ROOT/local/share/texmf/ into your home texmf directory with a command like (SAGE_ROOT=/opt/sage-x.x.x…./)

    $ cp -R SAGE_ROOT/local/share/texmf/tex TEXMFHOME

    where SAGE_ROOT is, as usual, replaced with the location of your Sage installation and TEXMFHOME is the result of the kpsewhich command above.

    Check home folder, is there any texmf folder? If not , then TEXMFHOME will surely there. Copy all file in TEXMFHOME

    $ cd /TEXMFLOCAL/generic/sagetex
    $ sudo cp * /usr/share/texmf-texlive/tex/latex/sagetex

Check If it works:

  •  Type in the following code :-
    A(l,b) = l*b
    l = 2
    b= 4
    area = A(l,b)
    Using formula
    A = \sage{latex(A(l,b))}
    for area $A = \sage{area.n(digits=2)}$

    Save it with “.tex” extesnion say : test.tex

  • Now write a script for running sage with latex.
    mkdir Test
    cd Test
    latex test.tex
    sage test.sagetex.sage
    pdflatex test.tex
    evince test.pdf
    Save it as ".sh" extesion file say : test.sh 
    Now run 
    $ sh test.sh