Setting environment variables in ubuntu

Posted on 2006-04-06
Last Modified: 2013-11-15
I'm trying to permanently set some environment variables in ubuntu.  I want to set CPATH and LD_LIBRARY_PATH.  So, I go to /etc/profile and add in the following commands:

export CPATH="/mypath"
export LD_LIBRARY_PATH = "/mypath"

I restart Linux, and when I type echo $CPATH on the bash terminal, my specified path does not appear.  The variable is empty.

So, I have to keep typing export CPATH="/mypath" everytime I open up a bash window.  How do I set these variables permanently?

Question by:chsalvia
    LVL 3

    Accepted Solution

    try putting in .~/bashrc  in your home directory.

    This will only work for that user however.  It seems strange that it doesn't work in /etc/profile, it should.    Look in ~/.bash_profile ~/.bash_login and ~/.bashrc to make sure it's not getting set to null e.g.  export CPATH;
    LVL 87

    Expert Comment

    Did you try it without the "export"?

    Author Comment

    Okay, I got it working.  

    For some reason ubuntu ignored my commands when I placed them in /etc/profile or in ~/.bash_profile or other user-specific settings files.

    It only worked when I placed it in /etc/bash.bashrc


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. Once you open the link you will see …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now