The equilibrium equations and the functional for tubing buckling in arbitrary straight wells are derived. The entire buckling process of tubing in deviated wells is analyzed for the first time by utilizing the finite element method. The effects of gravity and torques on the buckling are included in the analyses and the calculated results are well compared with existing solutions. It is shown that the buckling only occurs at the lower portion of the tubing where the axial load is the largest, and the contact force of the well, the bending moment of the tubing and the buckling displacement of this portion vary periodically. The buckling spreads upwards from the bit with the increase of axial load. There is no buckling at the upper portion of the tubing where the bending moment is zero. And the contact force of this section increases only slightly with the increase of the axial load. With the increase of the deviation angle, the length of buckling portion and buckling displacement amplitude decrease, the contact force increases with the increase of load at the upper portion and its amplitude decreases at the lower buckling section, the bending moment remains zero at the upper portion and its amplitude decreases at the lower buckling portion. The buckling displacement increases with the increase of the torque, but the increment is very small.